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.

DefinePlugin not working with destructure of multiple env vars

See original GitHub issue

Do you want to request a feature or report a bug? Bug

What is the current behavior? Using const { a, b } = process.env results in a client-side exception, where both variables have been defined using DefinePlugin.

Note: const { a } = process.env works perfectly

If the current behavior is a bug, please provide the steps to reproduce. Compile const { a, b } = process.env with Babel and the DefinePlugin, and notice that code intended for the client contains reference to process.env which does not exist in the browser environment, and throws exceptions

What is the expected behavior?

  1. Constants a and b in the example above should be replaced with the values provided to DefinePlugin.
  2. No exceptions should be thrown when loading the bundle into a browser environment.

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

Chrome 59 / node:v8.1.2 / yarn v0.24.6 / webpack v3

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sokracommented, Jul 11, 2017

You could try this:

new DefinePlugin({
  "process.env": {
    a: JSON.stringify("a"),
    b: JSON.stringify("b")
  }
})
0reactions
mattfyshcommented, Jul 14, 2017

Thanks 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing environment-dependent variables in webpack
There are two basic ways to achieve this. DefinePlugin. new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify(process.env.
Read more >
Webpack DefinePlugin, Webpack DefinePlugin not working ...
The DefinePlugin is a direct text replacement, similar to macros in C. Webpack ... DefinePlugin not working with destructure of multiple env vars...
Read more >
Environment Variables : Webpack config using DefinePlugin
In simple terms, Environment Variables are variables that are set depending on the computer (server) the software is running on.
Read more >
Managing Front-end JavaScript Environment Variables
env files with different suffixes contain variables for other environments. Here are some examples: .env.development (used when running an app ...
Read more >
Environment Variables - Gatsby
Loading environment variables into Node.js requires a small code snippet. In development, Gatsby will load environment variables from a file named .env.
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