Bug report
Describe the bug
Currently, Next.js only supports three different values for process.env.NODE_ENV (as documented here): development, production, and test.
When running NODE_ENV='test' next build, Next.js loads the right .env.test files but fails to properly replace process.env.NODE_ENV references with test (instead of production).
Previous issues (e.g. #9123, #12772) have requested support for more environment variables. This is not what this issue is about. This is an issue with behaviour that Next.js has already documented as supported (e.g. @Timer says that test is supported in this comment).
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Clone this repository:
$ git clone https://github.com/nicholaschiang/env-demo && cd env-demo
- Install dependencies:
- Build the app using the
test environment:
- Start the app using the
test environment:
- Visit the API route at http://localhost:3000/api/env and notice that the JSON response contains
production instead of test. This is because Next.js hardcodes (i.e. replaces) the process.env.NODE_ENV variable to production when running next build. This is not ideal when you want to use the NODE_ENV variable to trigger certain behavior during tests (e.g. accessing different Algolia search indexes).
Expected behavior
When running next build with the NODE_ENV set to test, Next.js should properly replace process.env.NODE_ENV references with test instead of production.
System information
- OS: PopOS 20.x
- Version of Next.js: 9.5.3
- Version of Node.js: 12.18.3
Additional context
This can be used to switch between outside resources (e.g. using a different set of Algolia indexes than the ones used in production) during tests. While this might not be ideal, it's required when running integration tests for me (because I can't easily stub out Algolia's search capabilities).
Bug report
Describe the bug
Currently, Next.js only supports three different values for
process.env.NODE_ENV(as documented here):development,production, andtest.When running
NODE_ENV='test' next build, Next.js loads the right.env.testfiles but fails to properly replaceprocess.env.NODE_ENVreferences withtest(instead ofproduction).Previous issues (e.g. #9123, #12772) have requested support for more environment variables. This is not what this issue is about. This is an issue with behaviour that Next.js has already documented as supported (e.g. @Timer says that
testis supported in this comment).To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
testenvironment:testenvironment:productioninstead oftest. This is because Next.js hardcodes (i.e. replaces) theprocess.env.NODE_ENVvariable toproductionwhen runningnext build. This is not ideal when you want to use theNODE_ENVvariable to trigger certain behavior during tests (e.g. accessing different Algolia search indexes).Expected behavior
When running
next buildwith the NODE_ENV set totest, Next.js should properly replaceprocess.env.NODE_ENVreferences withtestinstead ofproduction.System information
Additional context
This can be used to switch between outside resources (e.g. using a different set of Algolia indexes than the ones used in production) during tests. While this might not be ideal, it's required when running integration tests for me (because I can't easily stub out Algolia's search capabilities).