Add support for custom environments (Next 9.4)
See original GitHub issueFeature request
Is your feature request related to a problem? Please describe.
Currently, built-in environments allows only .env.development
and .env.production
environments, so when you run yarn dev
it uses .env.development
or .env.local
and when you do yarn build
, then yarn start
it uses .env.production
environment. But there’s no way to use a staging environment for example, like .env.staging
, there’s no way to run app with staging environment, if we try to NODE_ENV=staging yarn build && yarn start
we get an error: “https://github.com/zeit/next.js/blob/master/errors/non-standard-node-env.md”, and it won’t have effect, because NODE_ENV
would be production anyway, it’s being overwritten.
Describe the solution you’d like
There should be a way to set environment when you run your app, like NODE_ENV=staging/prestaging yarn build && yarn start
, etc. In CRA i use it this way:
"build:staging": "env-cmd -f .env.staging yarn build",
"build:prestaging": "env-cmd -f .env.prestaging yarn build"
Would be nice to have the same, but built-in in Next.
PS
"build:staging": "env-cmd -f .env.staging yarn build && yarn start"
this actually works with Next either, though NODE_ENV
would be set to “production”.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:19
- Comments:12 (4 by maintainers)
Top GitHub Comments
We already give you flexibility to choose from 8 different files, which should be enough:
.env
.env.local
.env.development
.env.development.local
.env.test
.env.test.local
.env.production
.env.production.local
https://nextjs.org/docs/basic-features/environment-variables#exposing-environment-variables
This has been the standardized way that people load
.env
files for a long time and has prior art:Hence why I don’t think introducing even more ways to load .env files is a feasible idea. Supporting 8 different files was already a stretch but it was what’s mostly supported as said.
I would say that .env.staging is probably a common enough use-case that it should be supported out-of-the-box