-
-
Notifications
You must be signed in to change notification settings - Fork 643
Description
Describe the bug
When passing env vars to webpack cli using --env, if the value of the variable passed is empty, then the resulting variable name and value is parsed incorrectly. As an example, webpack --env TEST="" results in the following env:
{
WEBPACK_BUNDLE: true,
WEBPACK_BUILD: true,
'TEST=': true
}
What is the current behavior?
Empty variables passed to --env like --env VAR="" or --env VAR=$NOT_DEFINED result in the env object containing property names like VAR= with the value true.
To Reproduce
Minimal webpack.config.js demonstrating behavior:
import { fileURLToPath } from "node:url";
export default (env) => {
console.log(env);
return {
mode: "production",
entry: "./main.js",
output: {
path: fileURLToPath(new URL(".", import.meta.url)),
filename: "main.bundle.js",
},
};
};Steps to reproduce the behavior:
$ npx webpack --env TEST1="" --env TEST2=$NON_EXISTENT_ENVVAR --env TEST3=
Expected behavior
Empty variables could be represented as one of null, undefined, or "", but certainly should not be true, and the property name should not include the =.
Screenshots
N/A
Please paste the results of npx webpack-cli info here, and mention other relevant information
$ npx webpack --env TEST1="" --env TEST2=$NON_EXISTENT_ENVVAR --env TEST3=
{
WEBPACK_BUNDLE: true,
WEBPACK_BUILD: true,
'TEST1=': true,
'TEST2=': true,
'TEST3=': true
}
asset main.bundle.js 50 bytes [compared for emit] [minimized] (name: main)
./main.js 28 bytes [built] [code generated]
webpack 5.73.0 compiled successfully in 82 ms
Additional context
None