npm run build hangs forever
Bug report
Describe the bug
npm run build with invokes 'next build' is hanging forever.
To Reproduce
Cannot specify steps to reproduce because it suddenly not
Expected behavior
It should build normally so that I can run npm start.
Screenshots
If applicable, add screenshots to help explain your problem.

System information
- OS: [e.g. macOS, Windows]
- Browser (if applies) [e.g. chrome, safari]
- Version of Next.js: [e.g. 6.0.2]
Additional context
Add any other context about the problem here.
I have tried to remove node_modules folder and npm install again, still it does not work.
Without a reproduction, we can't really help as you can understand. The Next.js test suite tests next build next start next a custom server.js etc. before automatically publishing to npm we run the test suite. If it fails on even 1 test we don't publish a release.
@timneutkens Thank you. Is there anyway to debug into next build process?
Try adding https://github.com/lucleray/next-progressbar, this will be a default soon.
@timneutkens That's so cool! At least I could know what is happening behind the scene.
The situation look a little bit brighter now.
Building server side code is hanging randomly as below

Another build:


How come the total number of modules in server changes across builds? The first image is 124 and the second is 119.
Hi @timneutkens I have found the way to reproduce the error. Would you help me to have a look into it?
Extract the zip file and run
npm install
npm run build
The build command will stuck at 91% for client side as could be seen in below image
next build error.zip
Thanks a lot for your help.
yarn build
yarn run v1.7.0
warning package.json: No license field
$ next build
✔ success server compiled in 1s 19ms
✔ success client compiled in 3s 978ms
Stats by Ext
╔═══════╤══════════╤══════╤══════════════╤══════════════════╗
║ Ext │ Requests │ Time │ Time/Request │ Description ║
╟───────┼──────────┼──────┼──────────────┼──────────────────╢
║ js │ 14 │ 59ms │ 4ms │ JavaScript files ║
╟───────┼──────────┼──────┼──────────────┼──────────────────╢
║ Total │ 14 │ 59ms │ │ ║
╚═══════╧══════════╧══════╧══════════════╧══════════════════╝
Stats by Loader
╔══════════════╤══════════╤══════╤══════════════╤══════════════╗
║ Loader │ Requests │ Time │ Time/Request │ Description ║
╟──────────────┼──────────┼──────┼──────────────┼──────────────╢
║ babel-loader │ 14 │ 59ms │ 4ms │ Babel Loader ║
╟──────────────┼──────────┼──────┼──────────────┼──────────────╢
║ Total │ 14 │ 59ms │ │ ║
╚══════════════╧══════════╧══════╧══════════════╧══════════════╝
✨ Done in 5.10s.
Runs fine for me, maybe try removing package-lock.json and node_modules and reinstalling the dependencies 🤔
:( I run on ubuntu linux subsystem on Windows. Could this be the problem?
Thank you. It works well on Virtual Machine.
Could be hidden error anyway but I would skip it for now. Thank you.
I was building fine on WSL with Next 6. I just upgraded to 7 and now my build seems to hang forever.
[11:21:40 PM] Compiling client
[11:21:40 PM] Compiling server
> Using external babel configuration
> Location: "/mnt/c/users/Adam/code/gell/gell-client/.babelrc"
[11:21:49 PM] Compiled server in 9s
I use WSL as a workaround to make builds with paths matching linux. As a workaround to that workaround I am now using AWS CodeBuild.
I have the same issue on WSL with the exact same working copy which works well on macos (no npm i, just a plain copy of everything). I'll try to produce a minimal repro, but seeing other exact issues I don't think it's a standalone case. Important thing to note, this happens on the native (not mounted) drive.
Experiencing this issue.
in my case it hangs inside an ec2 micro instance when trying yarn run build. it sometimes builds sucessfully.
- Removing yarn-lock.json, removing node_modules, then yarn, then yarn run build. same result.
- Removing package-lock.json, removing node_modules, then npm install, then npm run build. same result.
from my local dev machine, everything build as normal. could it be a machine out of memory issue?
In my case, I accidentally have another node_modules folder inside my node_modules folder. When I removed that unnecessary node_modules. It worked well and fast
Having the exact same problem with WSL.
In our case, we had required in next.config.js a module that did a fs.watch and this made the build process hang forever.
The same thing can happen with setTimeout and setInterval calls for modules that are required during the build process.
This answer helped me debug the problem: https://stackoverflow.com/a/32617487/873227
I added those console.log statements in the next-build script to see what was causing it to hang.
I'm having the same issues here after upgrading to next 9. WSL also. It would be nice to have some debug output.
I'm having the same issue as well.
@DMomplaisirASC probably a good idea to read https://twitter.com/timneutkens/status/1154351050700333056
If anyone needs to test this issue, I have a repo which is affected with the same issue.
- Git clone https://github.com/AmherstStudent/amherst-student-site
- cd into client
- yarn install,
- yarn run build
At this point - you will see it stalled. please help.