Next.js: npm run build success but got an error when I run next start

Created on 31 Jul 2017  路  19Comments  路  Source: vercel/next.js

I execute npm run build success but got an error message

> Could not find a valid build in the '.next' directory! Try building your app with 'next build' before starting the server.

I try removing node_module and reinstall them but still got an error.

Most helpful comment

Try running npm run build then run npm start again it should work

All 19 comments

is your script build in package.json actually doing next build ?

yes
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "next start -p 80 server.js",
"start2": "next start server.js"
},

remove the .next folder and try again

not work.

I found this https://github.com/arunoda/next.js/blob/6d0511b96ab4d32b09879ecff53fa46e18f93fb1/bin/next-start

if (!existsSync(resolve(dir, '.next', 'build-stats.json'))) {
console.error(> Could not find a valid build in the '.next' directory! Try building your app with 'next build' before starting the server.)
process.exit(1)
}

Mmmm, try not to use next start in the script start and use NODE_ENV=production server.js instead

Wow thanks it works !

I have the same issue, next build works fine but next start fails. No custom server. next build doesn't seem to create a build-stats.json when I run it.

@dbkaplun can you share a repo ?

Here's the repo: https://github.com/dbkaplun/dbkaplun

UPDATE: glitch has since been fixed, but I'm not sure how.

your project worked very well with me
working

with next 3.0.1-beta.17 - node 8.0.0 - npm 5.4.2
Maybe you have a lower version of node ?

btw nice canvas :D

@dbkaplun I am having the same issue - how did you resolve yours? I checked your repo and can't find the glitch.

I can confirm i am seeing this, when I run next in development mode

Deleting .next folder and restarting dev server fixed the problem.
I am using nodemon to run next in dev mode after using babel-register. So I am guessing something go out of wack.

Another updated, it fixed the issue briefly. Now it started doing it all over again.

Try running npm run build then run npm start again it should work

thanks @MiguelCedric . worked for me

@lfades could you please tell me that what these are doing:
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
I just started with next.js and I want to know wy thses are used.

@PiyankaYadav When you're using a custom server next start will not start your server, therefore you need to use node and start Next.js inside your node server.

Side note: Don't use a custom server if you're not 110% sure that you need one.

Was this page helpful?
0 / 5 - 0 ratings