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
Async chunk loading breaks complex expressions in globalObject option #12924
Comments
Without the parenthesis this resulted in invalid code ``` var chunkLoadingGlobal = typeof self !== 'undefined' ? self : this["webpackChunkngHotReloadCore"] = ``` See webpack/webpack#12924
To be honestly using |
This issue had no activity for at least three months. It's subject to automatic issue closing if there is no activity in the next 15 days. |
Issue was closed because of inactivity. If you think this is still a valid issue, please file a new issue with additional information. |
Still valid |
@alexander-akait I think better to add notes to docs. |
Bug report
What is the current behavior?
generates code
The ternary expression for
globalObject
isn't protected as an expression, but gets mixed with the surrounding code.In case the condition is true (
typeof self !== 'undefined'
) and consequent path is taken, the result of this expression ends up being the equivalent ofwhich then throws in the next line
Similar code also gets generated to the async chunk
which would also fail if the execution ever got that far.
If the current behavior is a bug, please provide the steps to reproduce.
Full minimal reproducible example in noppa/webpack-global-object-issue-repro.
What is the expected behavior?
The code in
globalObject
option should be treated as an arbitrary expression and either lifted to a variable or wrapped in parenthesisThe problem is easily enough fixed on the user's side:
and I get that this issue could end up closed as "working as intended". However, I think that this limitation should then at least be mentioned in the docs and/or some kind of warning should be given. The nasty thing about the current behavior is that the code only breaks under very specific conditions:
globalObject
is only used in expression})(typeof self !== 'undefined' ? self : this, function() {
which doesn't break the way the
chunkLoadingGlobal
code does. Simply adding/* webpackMode: "eager" */
to the import will "fix" the issue.self
is defined) but not in Node.Thus, the broken
globalObject
code is already widely used in the wild: grep.app search for unparenthesized ternaries in globalObject option.I believe that at least these issues could be caused by this:
jsonpFunction
didn't fix the issue for themOther relevant information:
webpack version: 5.26.3 and 4.46.0
Node.js version: 15.6.0
Operating System:
Additional tools:
The text was updated successfully, but these errors were encountered: