Environment variables from `.env` are not picked up by the Node process
See original GitHub issueCurrent Behavior
With the latest version of nx, it seems like the env vars in .env
are no longer picked up in Node/Nest apps (possibly others).
Some of the env vars do appear to be set:
console.log(Object.keys(process.env))
[
'NODE_ENV',
'NX_CLI_SET',
'NX_INVOKED_BY_RUNNER',
'NX_WORKSPACE_ROOT',
'NX_TERMINAL_OUTPUT_PATH',
'NX_STREAM_OUTPUT',
'NX_TASK_TARGET_PROJECT',
'NX_TASK_HASH'
]
Expected Behavior
Env vars defined in .env
should be available on process.env
Steps to Reproduce
Repro here: https://github.com/beeman/nx-env-vars-issue
- create a new repo
- add @nrwl/nest or @nrwl/node and create an app
- add an env var to
.env
- log out
process.env
- see that the env var from
.env
is not there
Failure Logs
No logs
Environment
> NX Report complete - copy this into the issue template
Node : 16.16.0
OS : darwin arm64
yarn : 1.22.19
nx : 14.7.6
@nrwl/angular : Not Found
@nrwl/cypress : Not Found
@nrwl/detox : Not Found
@nrwl/devkit : 14.7.6
@nrwl/eslint-plugin-nx : 14.7.6
@nrwl/expo : Not Found
@nrwl/express : Not Found
@nrwl/jest : 14.7.6
@nrwl/js : 14.7.6
@nrwl/linter : 14.7.6
@nrwl/nest : 14.7.6
@nrwl/next : Not Found
@nrwl/node : 14.7.6
@nrwl/nx-cloud : 14.6.2
@nrwl/nx-plugin : Not Found
@nrwl/react : Not Found
@nrwl/react-native : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : Not Found
@nrwl/web : Not Found
@nrwl/workspace : 14.7.6
typescript : 4.8.3
---------------------------------------
Local workspace plugins:
---------------------------------------
Community plugins:
Issue Analytics
- State:
- Created a year ago
- Reactions:15
- Comments:8 (3 by maintainers)
Top Results From Across the Web
node.js - NodeJS not recognizing .env file - Stack Overflow
In the file you are using environment variables, As early as possible, require the "dotenv" and in the config() method, specify the path...
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 >npm dotenv environment variables not recognized in nodejs ...
In each of the config files I am not able to access any properties of the process.env object that are defined in the...
Read more >Node Environment Variables: Process env Node
Node environment variables are strategies to define and consume environment-specific configurations and process env node. Learn how.
Read more >5 reasons why your .env environment variables don't work
1. Your framework doesn't automatically load .env files. · 2. You added or otherwise updated your .env file after starting your server. ·...
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
The fix landed on master, but it’s not released yet. I guess it will be available in 14.7.9 😉
I can confirm that this issue is also present with Nest as well regarding environment variables (provided from CLI).