-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.env NODE_PATH is not working in v1.1.0 #3939
Comments
My humble findings. |
You can not override environment variables that already exist. Default Node installation exposes such env var so you can't override it. Consider using nvm. It makes Node version switching easier, also does not pollute |
@miraage, of course! That would not be a good practice. I should probably clarify myself. I propose expanding NODE_PATH with the results from from dotenvFiles.forEach(dotenvFile => {
if (fs.existsSync(dotenvFile)) {
var results = require('dotenv-expand')(
require('dotenv').config({
path: dotenvFile,
})
);
if (results.parsed.NODE_PATH !== undefined) {
process.env.NODE_PATH += results.parsed.NODE_PATH;
}
}
}); |
I don't think it makes a lot of sense to treat I strongly recommend against setting a global |
It doesn't, make a lot of sense. It is just that the docs are not aligned with the feature set.
I think it would be best to just remove this line from the docs and close the issue. Another idea, would be to add |
I use the NODE_PATH variable for absolute imports, is there any other solution to this? |
setting |
@yasharma this is the correct behavior -- the environment variable set in your shell will always win over one in a |
@Timer yes that's correct , however if i remove shell environment variable and want to use .env vars , its not working in that case, setting |
That problem caused me a big headache. Thanks for everyone. zo/ |
bug
In reference to the same issue: #2230
NODE_PATH is ignored when defined in .env file.
And that contradicts the latest docs.
Why does it happen?
It happens because NODE_PATH should be configured when
config/env.js
executes.And
dotenv
module does not modify existing variables.create-react-app/packages/react-scripts/config/env.js
Lines 36 to 49 in 5348d6e
So the code will simply fail to append NODE_PATH from an
.env
file toprocess.env.NODE_PATH
variable that is used to provide this featurecreate-react-app/packages/react-scripts/config/env.js
Lines 60 to 65 in 5348d6e
Solution
Manually add NODE_PATH string received from the
dotenv.configure
parsed
property.The text was updated successfully, but these errors were encountered: