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
EnvironmentPlugin: destructuring process.env doesn't work #5392
Comments
@EvgenyOrekhov
Running
With
I get the documented output of
Should the |
@ismail-syed Yes, sorry, copy-paste error. |
That's because under the hood, EnvironmentPlugin uses DefinePlugin to perform text replacement, which means that it only swaps the text |
Any news here since summer 2017 ? Just bumped into the problem and it's kind of (very) annoying when you have dozens of Will try to work on a PR if nobody's on it. |
I'm still waiting |
i have a similar issue i think? i have code like: if (process && process.env && process.env[key]){
json = process.env[key];
} i currently use the new webpack.DefinePlugin({
'process.env': {
MY_CONFIGS: JSON.stringify(process.env.MY_CONFIGS)
}
}) which ends up replacing every instance of Object({ MY_CONFIGS: '{"stuff": "things"}' }) where is there a way to simply set a key on |
|
@lutzk - that's what i thought as well but since i'm doing a dynamic lookup - |
ah ok that might be youre telling the plugin to set thats why |
@lutzk - yep, that's why i was asking:
|
Had this working with envify / Gulp. Moving to Webpack breaks all that.. |
I know the people asking for what's up or say +1 are annoying but this is "P2: Very Important" issue yet there is no update for 2 years now so @sokra or the rest of the maintainers what do you think about this issue. Maybe fix it in the V5 ? |
Automatic Node.js Polyfills removed in @sokra @evilebottnawi this can be closed |
@vankop Hi! what if someone still wants to use |
@xeptore can you provide reproducible test repo with example of the problem? |
@evilebottnawi of course, here is the link to it: |
@xeptore To be honestly it is the bug and feature, |
@evilebottnawi yes. it's replacing based on tokens, and destructing is not exactly what it should replace. i play around with parsed version of both examples in this gist and it doesn't seem to be much difference between those trees. maybe one step further :) |
Hello, |
> Trying to destructure process.env variables won't work due to > the nature of webpack DefinePlugin. > https://nextjs.org/docs/api-reference/next.config.js/environment-variables webpack/webpack#5392 (comment)
> Trying to destructure process.env variables won't work due to > the nature of webpack DefinePlugin. > Source: https://nextjs.org/docs/api-reference/next.config.js/environment-variables More info: webpack/webpack#5392 (comment)
> Trying to destructure process.env variables won't work due to > the nature of webpack DefinePlugin. > > Source: https://nextjs.org/docs/api-reference/next.config.js/environment-variables More info: webpack/webpack#5392 (comment)
> Trying to destructure process.env variables won't work due to > the nature of webpack DefinePlugin. > > Source: https://nextjs.org/docs/api-reference/next.config.js/environment-variables More info: webpack/webpack#5392 (comment)
closing in favor of #14800 pls track problem there |
Do you want to request a feature or report a bug?
report a bug
What is the current behavior?
Destructuring
process.env
doesn't work.console.log(MY_VAR);
logsundefined
Steps to reproduce.
webpack.config.js
main.js
command
What is the expected behavior?
console.log(MY_VAR);
should log "test"Node.js version: 8.2.1
webpack version: 3.4.1
OS version: Ubuntu 17.04
The text was updated successfully, but these errors were encountered: