Local environment variables do not overwriting stage environment variables
See original GitHub issueBug report
Describe the bug
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"
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Create a
.env.development
file and add a variable. - Create a
.env.local
file and add the same variable. - console log the variable in a page
- See the development var and not the local one.
Expected behavior
Local variables should overwrite previous variable set in both .[stage]
and .[stage].local
env files.
System information
- OS: macOS
- Version of Next.js: 9.4.0 & 9.4.1
- Version of Node.js: 10.16.3
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Local environment variables do not overwriting stage ... - GitHub
Expected behavior. Local variables should overwrite previous variable set in both .[stage] and .[stage].local env files.
Read more >Dotenv unable to overwrite key value pair - Stack Overflow
Environment variables that are already set will not be overwritten, that means that the command line variables have a higher priority over ...
Read more >Overwriting environment variables when invoking local function
Hey,. I am setting environment variables in serverless.yml like this: environment: DYNAMODB_TABLE: Ref: DynamodDBTable. That does not work ...
Read more >Is it possible to declare a local variable without overriding the ...
A workaround is to save and restore the value. That does mean listing the variables you want to save. You can indeed clash...
Read more >Working with Environment Variables in Node.js - Twilio
Environment variables are a great way to configure parts of your Node.js application. Learn how to work with them using helpful tools such ......
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
Hey,
Maybe I misunderstand but with
9.4.4
when usingnext start
ornext 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. ThanksThis 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.