Failed To Compile - npm run build after upgrading Next JS
See original GitHub issueBug report
Describe the bug
I upgraded next 5.1.0 to next 8.1.0 using this command
npm i --save next@latest react@latest react-dom@latest
when I’m running npm run build command, this error occurs
λ npm run build
> inviteman@0.0.1 build D:\Documents\GitHub\inviteman
> next build src && npm run build:server
Creating an optimized production build ...
Failed to compile.
../node_modules/next-server/dist/lib/head-manager-context.js
Error: .env["debug"] must be an object, or undefined
at Array.forEach (<anonymous>)
> Build error occurred
Error: > Build failed because of webpack errors
at Object.build [as default] (D:\Documents\GitHub\inviteman\node_modules\next\dist\build\index.js:192:15)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! inviteman@0.0.1 build: `next build src && npm run build:server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the inviteman@0.0.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Irene\AppData\Roaming\npm-cache\_logs\2019-04-21T15_52_07_208Z-debug.log
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Upgrade next JS
npm i --save next@latest react@latest react-dom@latest - Run
npm run build - See error
System information
- OS: Windows 10
- Version of Next.js: 8.1.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
javascript - Next.js - `npm run build` failed - Stack Overflow
I have package.json in project folder. when I run npm run dev it works just fine. I don't know why he is complaining ......
Read more >Failed To Compile - npm run build after upgrading Next JS
Bug report Describe the bug I upgraded next 5.1.0 to next 8.1.0 using this command npm i --save next@latest react@latest react-dom@latest ...
Read more >Migrating from Create React App - Next.js
Let's walk through a series of steps to complete the migration. Updating package.json and dependencies. The first step towards migrating to Next ......
Read more >Install Next.js on Windows | Microsoft Learn
npm run build for compiling your project. npm start for starting your app in production mode. Open the WSL terminal integrated in VS...
Read more >Netlify Build Deployment Error because of Webpack - Support
Site Name: MMODoctor Framework: NextJS Application Error: Webpack Build Error ... PM: Installing NPM modules using NPM version 7.21.0 8:54:00 PM: npm WARN ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Please provide a full reproduction.
Not on the Next team, but usually the most helpful thing is a link to a repository of a stock install of Next.js with the minimal amount of code and npm packages needed to recreate the error.
Quite often, this process of stripping down the code/packages and trying to reproduce the problem will lead you to your own solution or to find that the problem was not with Next but with your own custom code or a third party package.
Having done this, you now either have strong case to show that the issue is with Next, or you know the problem is with a third party package and can approach them, or you have a lot of context to ask for help (https://spectrum.chat/next-js being the preferred place to ask).
The final benefit is that you’ve saved the Next team from having to do this for you, and maybe they can use that saved time to further improve Next for us all.