On a fresh setup with Next 2.0 I got this error on npm start (next start), solved running npm run build (next build) first. Is that an expected behaviour? should it be added to the documentation?
@hsuastegui For development you need to run npm run dev (i.e next) to start dev server. And for production deployment you need to run npm run build (i.e next build) and then npm run start (i.e next start ) to start production server. Both of these are documented here.
Got same problem after create custom server with express
https://github.com/zeit/next.js/tree/master/examples/custom-server-express
Error: Cannot find module '/Users/rohmanhm/Desktop/Code/Learn/NextJS/basic/.next/build-stats.json'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at new Server (/Users/rohmanhm/Desktop/Code/Learn/NextJS/basic/node_modules/next/dist/server/index.js:100:30)
at module.exports (/Users/rohmanhm/Desktop/Code/Learn/NextJS/basic/node_modules/next/dist/server/next.js:10:10)
at Object.<anonymous> (/Users/rohmanhm/Desktop/Code/Learn/NextJS/basic/server.js:9:13)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
@rohmanhm That error occurs if you run npm run start without npm run build these should be used in production . For development we should use npm run dev to start dev server. Please look at the npm scripts used in that example https://github.com/zeit/next.js/blob/master/examples/custom-server-express/package.json#L3-L5
So, if I use custom server it doesn't support Hot Reload?
@rohmanhm AFAIK Only client side code gets Hot reloaded, if you change any server side code you need to restart the server for those to take effect.
Thanks for you explanation @vinaypuppal , it helps a lot. You saved my time
Now, I use Nodemon to watch my changes on my server.
I'm having this issue even after running next build.
Edit: it seems my build was failing, but there's a promise somewhere that isn't handling rejections...

I'm checking if this is all me.
Reverting to 2.0.0-beta.41 fixes my issue. Something was introduced in 2.0.0-beta.42 that's causing my build to fail. My issue isn't related to this one tho, so I'll open a new issue and see if I can create a test case.
2.0.0-beta.41 maybe using Webpak@v1
since Webpack@v2, loader-utils change their API from .parseQuery() changed to .getOptions
it's just a warning
Thanks @vinaypuppal for helping us.
The warning comes from the babel-loader.
We can remove the warning, after babel 7 released.
See: https://github.com/zeit/next.js/issues/1387
I have the same problem. After running next build, there is no .next/ directory.
Same here
you need to run npm run build first, after that run npm run dev or npm run start for production
@rohmanhm The warning is irrelevant to my and @Larry850806's case. Note that we both ran the build already (next build is what npm run build does). @Larry850806 I fixed my issue by removing tests from the pages directory. See https://github.com/zeit/next.js/issues/1545.
@timmywil I also found that it was fixed after removing some directory in my project, but I not sure which file causing this issue. I'm trying to make a minimum repo to reproduce this issue now. Sorry for my poor English.
Not having a test folder over here :/
@Larry850806 @esteban-uo. I was having similar issue, no .next file after running npm run build. I solved it by running apt-get install libkrb5-dev as node-gyp was erroring out.
npm-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/root/.nvm/versions/node/v6.10.3/bin/node',
1 verbose cli '/root/.nvm/versions/node/v6.10.3/bin/npm',
1 verbose cli 'run',
1 verbose cli 'build' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected]~prebuild: [email protected]
6 silly lifecycle [email protected]~prebuild: no script for prebuild, continuing
7 info lifecycle [email protected]~build: [email protected]
8 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~build: PATH: /root/.nvm/versions/node/v6.10.3/lib/node_modules/npm/bin/node-gyp-bin:/srv/schooltext/frontend/node_modules/.bin:/root/.nvm/versions/node/v6.10.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
10 verbose lifecycle [email protected]~build: CWD: /srv/schooltext/frontend
11 silly lifecycle [email protected]~build: Args: [ '-c', 'next build' ]
12 silly lifecycle [email protected]~build: Returned: code: 137 signal: null
13 info lifecycle [email protected]~build: Failed to exec build script
14 verbose stack Error: [email protected] build: `next build`
14 verbose stack Exit status 137
14 verbose stack at EventEmitter.<anonymous> (/root/.nvm/versions/node/v6.10.3/lib/node_modules/npm/lib/utils/lifecycle.js:255:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (/root/.nvm/versions/node/v6.10.3/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:886:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid [email protected]
16 verbose cwd /srv/schooltext/frontend
17 error Linux 4.4.0-72-generic
18 error argv "/root/.nvm/versions/node/v6.10.3/bin/node" "/root/.nvm/versions/node/v6.10.3/bin/npm" "run" "build"
19 error node v6.10.3
20 error npm v3.10.10
21 error code ELIFECYCLE
22 error [email protected] build: `next build`
22 error Exit status 137
23 error Failed at the [email protected] build script 'next build'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the schooltext package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error next build
23 error You can get information on how to open an issue for this project with:
23 error npm bugs schooltext
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls schooltext
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
Check you node-debug.log
It seems like I have to run next build manually after every change, and after npm run dev to start the server again. Surely, this can't be the way this is supposed to work, when using a custom express server? Why are my client files not rebuilding automatically after running run dev?
Most helpful comment
@hsuastegui For development you need to run
npm run dev(i.enext) to start dev server. And for production deployment you need to runnpm run build(i.enext build) and thennpm run start(i.enext start) to start production server. Both of these are documented here.