Environment variables are loaded in the following order:
ready - started server on http://localhost:3000
info - Loaded env from .env.development.local
info - Loaded env from .env.development
info - Loaded env from .env.local
info - Loaded env from .env
However, vars in .env.local do not overwrite vars in .env.development. Is this to be expected?
The use case arises when a var in development should be overwritten when running locally. Say accessing the api.
// .env.development
NEXT_PUBLIC_API_URL="https://api.example.com"
// .env.local
NEXT_PUBLIC_API_URL="http://localhost:3000"
Steps to reproduce the behavior, please provide code snippets or a repository:
.env.development file and add a variable..env.local file and add the same variable.Local variables should overwrite previous variable set in both .[stage] and .[stage].local env files.
We'll take a look!
I think the order must just be reversed:
https://github.com/zeit/next.js/blob/canary/packages/next/lib/load-env-config.ts#L18
I upgraded from 9.4.2 to 9.4.4, the issue still persists.
Hey,
Maybe I misunderstand but with 9.4.4 when using
next start or next build - environment will be productionnext dev - environment will be developmentIn order to override these environments I can pass in NODE_ENV=development npm run build and this should set the environment to development?
My issue is even in doing this next will still load the .env. and .env.production files, should it not load the .env.development file instead? What am I missing to achieve this as I would like to load the correct files based on custom environments I set. Thanks
Most helpful comment
Hey,
Maybe I misunderstand but with
9.4.4when usingnext startornext build- environment will be productionnext dev- environment will be developmentIn order to override these environments I can pass in
NODE_ENV=development npm run buildand this should set the environment to development?My issue is even in doing this next will still load the
.env.and.env.productionfiles, should it not load the.env.developmentfile instead? What am I missing to achieve this as I would like to load the correct files based on custom environments I set. Thanks