Search code examples
deploymentbuildnext.jsvercel

npm run build error in nextJS and vercel deploy


I have an app already deploy on vercel , i change just a a content in a page and push it on git without problem(i make that many times without problem before), but now i can't execute npm run build return an error , the same error on vercel deploy. Can any one help me to fix this issue.

00:50:06.011 > next .next/build 00:50:06.209 > No such directory exists as the project root: /vercel/workpath0/portfolio/.next/build

the script in package.json

"scripts": {
"dev": "next dev",
"build": "next .next/build",
"start": "next start"

},

vercel deploy terminal


Solution

  • The reason its failing with "No such directory exists" is because the .next directory doesn't exist until you run next build, which is the command that generates the output.

    Change your build script to next build, like it shows in the Next.js docs, and it will work.