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
#7742 by @kentcdodds changed the webpack config for output.globalObject to be this instead of webpack's default window, so that webpack chunk loading would work in Workers.
Unfortunately, making the assumption that this is the global object isn't always safe because if the code is concatenated or otherwise wrapped into code that has "use strict" strict mode will also apply to inner functions within that scope, and this will be undefined in some cases, most notably in the webpack runtime chunk/code since itself contains code that executes inside of an IIFE and so this === undefined
I admit, this is very much an edge case and outside the normal usage of CRA. But if there's a fairly trivial way for us to solve this, it would notably help my use case because I cannot control the code provided to me--I would have to no longer support users who use CRA unless they ejected so that they could change that webpack config option. That's not your problem of course lol just clarifying why I'm checking in.
Wanted to at least open the dialog and see if someone had thoughts on a simple solution?
Did you try recovering your dependencies?
n/a
Which terms did you search for in User Guide?
globalObject, runtime, webpack, etc.
Environment
n/a
Steps to reproduce
Build a CRA project
Concatenate one or more of the chunks together, with the runtime.
Put "use strict" at the the top of the code.
Run the code in any supported JS env.
See error of this being undefined due to strict mode.
Expected behavior
Something other than this is used. I'm not immediately sure, since globalThis isn't supported in IE (which CRA supports) and forcing folks to include a polyfill is presumably off the table.
Actual behavior
TypeError: Cannot read property 'webpackJsonpsomeproject' of undefined because this is undefined under strict mode.
Reproducible demo
Non-trivial to provide, but if required I can consider making one. I think those who are familiar with how CRA + webpack builds work will likely know immediately what I'm referring to, but maybe not hehe 😄
The text was updated successfully, but these errors were encountered:
Describe the bug
#7742 by @kentcdodds changed the webpack config for output.globalObject to be this instead of webpack's default window, so that webpack chunk loading would work in Workers.
Unfortunately, making the assumption that this is the global object isn't always safe because if the code is concatenated or otherwise wrapped into code that has "use strict" strict mode will also apply to inner functions within that scope, and this will be undefined in some cases, most notably in the webpack runtime chunk/code since itself contains code that executes inside of an IIFE and so this === undefined
I admit, this is very much an edge case and outside the normal usage of CRA. But if there's a fairly trivial way for us to solve this, it would notably help my use case because I cannot control the code provided to me--I would have to no longer support users who use CRA unless they ejected so that they could change that webpack config option. That's not your problem of course lol just clarifying why I'm checking in.
Wanted to at least open the dialog and see if someone had thoughts on a simple solution?
Did you try recovering your dependencies?
n/a
Which terms did you search for in User Guide?
globalObject, runtime, webpack, etc.
Environment
n/a
Steps to reproduce
Build a CRA project
Concatenate one or more of the chunks together, with the runtime.
Put "use strict" at the the top of the code.
Run the code in any supported JS env.
See error of this being undefined due to strict mode.
Expected behavior
Something other than this is used. I'm not immediately sure, since globalThis isn't supported in IE (which CRA supports) and forcing folks to include a polyfill is presumably off the table.
Actual behavior
TypeError: Cannot read property 'webpackJsonpsomeproject' of undefined because this is undefined under strict mode.
Reproducible demo
Non-trivial to provide, but if required I can consider making one. I think those who are familiar with how CRA + webpack builds work will likely know immediately what I'm referring to, but maybe not hehe 😄
The text was updated successfully, but these errors were encountered: