globalThis does not work with stable namespace
yuri-voloshyn opened this issue · comments
globalThis does not work with stable namespace (core-js/stable/global-this), only with full (core-js/full/global-this)
Version: 3.32.2
What do you mean by "does not work"?
core-js/stable/global-this
imports core-js/es/global-this
that imports core-js/modules/es.global-this
that works as expected.
core-js/full/global-this
adds only core-js/modules/esnext.global-this
that also imports core-js/modules/es.global-this
- for backward compatibility with core-js@<3.3
.
Could you add a reproducible example?
Project to reproduce: https://github.com/yuri-voloshyn/core-js-issue-1290
Open build/index.html with Live Server
Open url in Safari 5.1
We will see the following messages in the console: https://github.com/yuri-voloshyn/core-js-issue-1290/blob/main/screenshot.jpg
In this example, in the bundle, require("core-js/stable/global-this")
is just removed and not imported:
// ...
!function() {
console.log("stable",window.globalThis);function load_full(){__webpack_require__(6060);}load_full();console.log("full",window.globalThis);
}();
I don't wanna dig into the reason, most likely it's related to your targets - anyway it's not a core-js
issue.
Yes, I see that import is not included. But why? We have the same targets for both namespaces.
I don't know how react-app-rewired
works with polyfills optimization, so at first glance, I can’t determine the reasons. It just removes this import at build. You could ask them.
I added react-app-rewired
to the example just to disable optimization, the same behavior is observed without it.
If it happens with @babel/preset-env
, ask here: https://github.com/babel/babel-polyfills - I don't know what else could remove this import.
The correct output should be
// ...
!function() {
__webpack_require__(9758);console.log("stable",window.globalThis);function load_full(){__webpack_require__(6060);}load_full();console.log("full",window.globalThis);
}();
and in this case, everything works fine.