`next/jest` sets `NODE_ENV` to `'production'`
See original GitHub issueRun next info
(available from version 12.0.8 and up)
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:24 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T8101
Binaries:
Node: 14.17.6
npm: 8.1.4
Yarn: 1.22.15
pnpm: N/A
Relevant packages:
next: 12.0.8-canary.17
react: 17.0.2
react-dom: 17.0.2
What version of Next.js are you using?
12.0.8-canary.17
What version of Node.js are you using?
14.17.6
What browser are you using?
N/A
What operating system are you using?
macOS 12.0.1 (21A559)
How are you deploying your application?
N/A
Describe the Bug
The next/jest
preset sets NODE_ENV
to 'production'
.
Users familiar with Jest will expect NODE_ENV
to be 'test'
when running tests. The documentation says:
Set to
'test'
if it’s not already set to something else.
In this case, NODE_ENV
is indeed set to 'test'
initially, but is replaced with 'production'
. I’ve verified this simply by console logging the environment in the test setup files, and again in a test. I did take a quick look, but wasn’t able to identify the cause.
This is related to #17032 and #17903.
Expected Behavior
When running tests in Jest, NODE_ENV
should be 'test'
.
To Reproduce
Create a new app using the Jest example:
npx create-next-app --example with-jest with-jest-app
Add the following line to the example test:
// __tests__/index.test.tsx
console.log(process.env.NODE_ENV); // production
Run:
npm test
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
nextjs - next build with NODE_ENV=development
If you next build && next start it will produce a production build. To achieve what you are trying to do use .env.development...
Read more >non-standard-node-env - Next.js
The greater React ecosystem treats NODE_ENV as a convention, only permitting three (3) values: production : When your application is built with next...
Read more >Set Environment Variables in Next.JS - Deni Apps
Before nextJS 9.4, we could use next.config.js to set up environment ... NODE_ENV !== ... and .env.production (production environment).
Read more >next.js multiple environments build | by Dzung Nguyen - Medium
So if you pass NODE_ENV=production to “run command”, Next will not treat your app as ... you can give me the feedbacks. Thank...
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 FreeTop 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
Top GitHub Comments
Hi, this has been updated in
v12.0.8-canary.18
of Next.js, please update and give it a try!Note: you may need to run
yarn jest --clearCache
for this change to take affect.Thanks @ijjk!