You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
have DefinePlugin plugin defined in the webpack config like this:
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
})
]
try to access NODE_ENV via destructuring: const { NODE_ENV } = process.env;
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:
The text was updated successfully, but these errors were encountered:
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.
NODE_ENV
via destructuring:const { NODE_ENV } = process.env;
Uncaught ReferenceError: process is not defined
However!
if you access NODE_ENV like
const NODE_ENV = process.env.NODE_ENV;
instead ofconst { 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:
The text was updated successfully, but these errors were encountered: