Issue while deploying Nextjs app (! Failed to install Node modules.)

In my case it was flag: “legacy-peer-deps=true” in “~/.npmrc” file, setting it to false and running “npm i” again solved the problem.