question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EnvironmentPlugin: destructuring process.env doesn't work

See original GitHub issue

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); 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:closed
  • Created 6 years ago
  • Reactions:42
  • Comments:20 (4 by maintainers)

github_iconTop GitHub Comments

23reactions
jt3kcommented, May 11, 2018

I’m still waiting

6reactions
sylvercommented, Apr 6, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found