Setting NODE_ENV to 'staging' causes builds to fail
See original GitHub issueBug report
Describe the bug
Setting NODE_ENV to ‘staging’ causes next build
to fail on a Webpack “unexpected token” error - presumably the first time it encounters JSX.
To Reproduce
- Create a Next.js app with JSX in it
NODE_ENV=staging npm run build
- ???
- Failure
Expected behavior
Probably shouldn’t fail.
Screenshots

System information
- OS: macOS, whatever Linux Heroku runs
- Version of Next.js: 9.2.0
Additional context
Add any other context about the problem here.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Setting NODE_ENV to 'staging' causes builds to fail #10129
Setting NODE_ENV to 'staging ' causes next build to fail on a Webpack "unexpected token" error - presumably the first time it encounters...
Read more >Do not use NODE_ENV for staging - Gleb Bahmutov
When running on staging or production, I set NODE_ENV variable on the server to staging or production . This value then lets my...
Read more >Why is process.env.NODE_ENV undefined? - Stack Overflow
process.env is a reference to your environment, so you have to set the variable there. To set an environment variable in Windows: SET...
Read more >Managing .env variables for provisional builds with Create ...
What if you want to setup .env.staging ? This article will show you how to manage environment variables for provisional builds.
Read more >Environment variables - AWS Amplify Hosting
In the Amplify console, choose App Settings, then choose Build settings. In the App build specification section, choose Edit. Add the environment variable...
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
Hi, setting
NODE_ENV
tostaging
instead of the default values we set is not ideal as this will cause things to potentially mismatch~One case of where this will cause problems is when bundling
react
if you setNODE_ENV
to a value other thanproduction
during a production build the development bundle will be used, see here for related code~EDIT: It looks we override this value during bundling so the above isn’t a concern although can lead to mismatches due to not overriding with
next start
or when loading Babel or Next configsThis issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.