Skip to content
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

Destructuring DefinePlugin variables causes runtime error #14883

Closed
villesau opened this issue Dec 1, 2021 · 1 comment
Closed

Destructuring DefinePlugin variables causes runtime error #14883

villesau opened this issue Dec 1, 2021 · 1 comment

Comments

@villesau
Copy link

villesau commented Dec 1, 2021

Bug report

What is the current behavior?

Destructuring DefinePlugin variables causes runtime error Uncaught ReferenceError: process is not defined

If the current behavior is a bug, please provide the steps to reproduce.

  1. have DefinePlugin plugin defined in the webpack config like this:
  plugins: [
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
    })
  ]
  1. try to access NODE_ENV via destructuring: const { NODE_ENV } = process.env;
  2. you get runtime failure Uncaught ReferenceError: process is not defined

However!

if you access NODE_ENV like const NODE_ENV = process.env.NODE_ENV; instead of const { NODE_ENV } = process.env; you don't get runtime error and everything works like expected.

What is the expected behavior?

Both ways of accessing the variable should be equal and should not cause runtime error.

It is pretty confusing and hard to debug problem and also problematic due to widely used prefer-destructuring eslint rule.

Other relevant information:
webpack version: 5.64.4
Node.js version: v16.13.0
Operating System: MacOS Big Sur
Additional tools:

@alexander-akait
Copy link
Member

Duplicate #14800, limitation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants