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.

webpack.DefinePlugin and process.env.DEBUG

See original GitHub issue

My webpack config:

...
plugins: [
  new webpack.DefinePlugin({
    'process.env': {
      NODE_ENV: JSON.stringify('production'),
      DEBUG: true
    }
  })
],

target: 'electron-main',
...

So webpack changes process.env.DEBUG = namespaces; to true = namespaces; which leading to error ReferenceError: Invalid left-hand side in assignment

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
Qix-commented, Dec 19, 2018

If you set a process.env field to null or undefined,

I know this is painful for some users, but debug is not the place to properly fix this. Instead, webpack needs to solve this as process.env has a very clear contract for what should be in it.

It is not debug’s job to clean up other peoples’ messes. Please open a ticket with them as this is indeed a bug or poor devexp on their part.

3reactions
thebigredgeekcommented, Sep 4, 2017

@wontem you have to escape values that you want assigned to actual variables. Otherwise, Webpack is going to REPLACE the variables with literal values.

Should look like this, afaik:

plugins: [
  new webpack.DefinePlugin({
    'process.env': {
      NODE_ENV: JSON.stringify('production'),
      DEBUG: JSON.stringify(true)
    }
  })
],
Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack.DefinePlugin and process.env.DEBUG · Issue #467
My webpack config: ... plugins: [ new webpack.DefinePlugin({ 'process.env': { NODE_ENV: JSON.stringify('production'), DEBUG: true } }) ], target: ...
Read more >
EnvironmentPlugin | webpack
webpack is a module bundler. ... EnvironmentPlugin is shorthand for using the DefinePlugin on process.env keys. ... NODE_ENV is defined DEBUG: false, }); ......
Read more >
EnvironmentPlugin
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 >
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 >
Environment Variables : Webpack config using DefinePlugin
What is Environment Variable ? “Environment variables are a set of dynamic named values that can affect the way running processes will behave...
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