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
Then run cd examples/multi-compiler && node build.js.
Whether you use my branch or the above patch, building the modified multi-compiler example will happily run without any errors.
The resulting code has process.env.ENV correctly interpolated to desktop or mobile per Webpack config, but the new unknown process.env.TESTING is erroneously left intact.
What is the expected behavior?
I expect building multi-compiler in the above branch (or the current webpack main with the patch applied) to fail per EnvironmentPlugin docs:
If an environment variable is not found during bundling and no default value was provided, webpack will throw an error instead of a warning.
Other relevant information:
webpack version: main branch 2e174de66
Node.js version: v20.18.0
Operating System: macOS and Rocky9 Linux
Additional tools:
The text was updated successfully, but these errors were encountered:
And if you have new webpack.EnvironmentPlugin(["ENV"]), it will throw an error when you don't have it in process.env, we never threw an error if we found the value in the source code.
I would recommend using a linter in this case if you want to prohibit the use of some values in the source code (in process.env).
Understood, thanks, sorry for misunderstanding! It was very surprising to see process.env.… in the built output but I now see that this is intended behavior.
If it's ok with you, I'll prepare a PR explaining this a bit more in the documentation?
Bug report
What is the current behavior?
Webpack configured to use
EnvironmentPlugin
will happily build code with unknown environment variables likeprocess.env.UNKNOWN
.If the current behavior is a bug, please provide the steps to reproduce.
I have created a fork of the webpack repo and tweaked an example to demonstrate the issue at https://github.com/fasiha/webpack/tree/example-environment-plugin. You can either check out that fork and branch and then run
or simply check out the current
main
branch and apply the following patch to modify one of the examples:Then run
cd examples/multi-compiler && node build.js
.Whether you use my branch or the above patch, building the modified
multi-compiler
example will happily run without any errors.The resulting code has
process.env.ENV
correctly interpolated todesktop
ormobile
per Webpack config, but the new unknownprocess.env.TESTING
is erroneously left intact.What is the expected behavior?
I expect building
multi-compiler
in the above branch (or the current webpackmain
with the patch applied) to fail per EnvironmentPlugin docs:Other relevant information:
webpack version:
main
branch 2e174de66Node.js version: v20.18.0
Operating System: macOS and Rocky9 Linux
Additional tools:
The text was updated successfully, but these errors were encountered: