-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
DefinePlugin breaks references to imports #18573
Labels
Comments
PR welcome, we need to skip replacing when it used as reference, thank you for a report |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
What is the current behavior?
When an imported identifier shadows a nested DefinePlugin definition, references to the import are broken when they are in a more complex expression (e.g. assignment to a new variable). This results in a
ReferenceError
being introduced.If the current behavior is a bug, please provide the steps to reproduce.
Added failing minimal test here: #18572
What is the expected behavior?
Other relevant information:
webpack version: 5.93.0
Node.js version: 20
Operating System: MacOS
Additional tools:
Note that this does not appear to be a recent regression, this has been broken for a long time.
I originally found this bug in this scenario:
Babel transforms this optional chaining into:
This bug is triggered by this code: webpack breaks the reference to the imported
process.env
within the chained logical expression, resulting in aReferenceError
in browsers becauseprocess.env
is obviously undefined.Notably, this code breaks with default webpack configuration, as
DefinePlugin
is automatically applied:webpack/lib/WebpackOptionsApply.js
Lines 569 to 574 in 277460b
The text was updated successfully, but these errors were encountered: