EnvironmentPlugin: destructuring process.env doesn't work
See original GitHub issueDo 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);
logs undefined
Steps to reproduce.
webpack.config.js
const path = require("path");
const {EnvironmentPlugin} = require("webpack");
module.exports = {
entry: "./main.js",
output: {
path: path.resolve(__dirname),
filename: "bundle.js"
},
plugins: [
new EnvironmentPlugin(["MY_VAR"])
]
};
main.js
const {MY_VAR} = process.env;
console.log(MY_VAR); // logs undefined
console.log(process.env.MY_VAR); // logs "test"
command
MY_VAR=test webpack
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
Issue Analytics
- State:
- Created 6 years ago
- Reactions:42
- Comments:20 (4 by maintainers)
Top Results From Across the Web
process.env undefined using DefinePlugin and DotEnv - Stack ...
1. Thank you! for me the issue was that I was destructuring the process.env: const { NODE_ENV } = process.env; which did not...
Read more >EnvironmentPlugin | webpack
The EnvironmentPlugin is shorthand for using the DefinePlugin on process.env keys. Usage. The EnvironmentPlugin accepts either an array of keys or an object ......
Read more >next.config.js: Environment Variables
Trying to destructure process.env variables won't work due to the nature of webpack DefinePlugin. For example, the following line: return ...
Read more >typescript - The webpack production mode can't even recognize ...
The webpack production mode can't even recognize destructuring. It can only naively replace literal occurrence of process.env.NODE_ENV. What is this?
Read more >Environment Variables in Next.js - Jake Trent
config() , and we destructure out the parsed object -- usually set on process.env , but now given to the webpack.EnvironmentPlugin -- which...
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 Free
Top 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
I’m still waiting
Any news here since summer 2017 ?
Just bumped into the problem and it’s kind of (very) annoying when you have dozens of
env
variables (literally).Will try to work on a PR if nobody’s on it.