question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug when using `globalThis` from core-js

See original GitHub issue

Bug report

What is the current behavior?

This code throws in IE8 with : Object doesn't support this action

(typeof globalThis !== "undefined") && (typeof globalThis.String !== "undefined")

If the current behavior is a bug, please provide the steps to reproduce.

Test results : https://mrhenry.github.io/web-tests/#8dda6a67-3527-4f7c-b2ab-0c6a455a1710

Test source code : https://github.com/mrhenry/web-tests/blob/main/specifications/tc39/ecma262/18.1.1.globalThis/test.pure.js

Transpiled/bundled code : https://github.com/mrhenry/web-tests/blob/main/specifications/tc39/ecma262/18.1.1.globalThis/test.babel_webpack.js

Error occurs on line 1092 : https://github.com/mrhenry/web-tests/blob/main/specifications/tc39/ecma262/18.1.1.globalThis/test.babel_webpack.js#L1092

HTML file with this code : https://gist.github.com/romainmenke/f3751b88a50b8433425a1f1058ed552d loading this file in IE8 will illustrate the error

Webpack config : https://github.com/mrhenry/web-tests/blob/main/webpack.config.js

Build with Webpack CLI : npm run webpack -- --entry $(mkfile_dir)test.pure.js --output-path $(mkfile_dir) --config webpack.config.js https://github.com/mrhenry/web-tests/blob/main/specifications/tc39/ecma262/18.1.1.globalThis/Makefile#L9

What is the expected behavior?

I expected no interrop issues with core-js globalThis

Other relevant information: webpack version: 5.52.1 Node.js version: 16.x Operating System: macos Additional tools: babel, core-js, preset-env

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zloirockcommented, Sep 12, 2021

@romainmenke I didn’t say that this will work in your case, I say that required ESM -> CJS Babel transform that does not use accessors. For my test cases, this transform is enough, you could try to use another - for example, default babel-plugin-transform-modules-commonjs (however, I’m not sure that it will work in all cases).

1reaction
zloirockcommented, Sep 12, 2021

You could try to use ESM -> CJS Babel transform that does not use accessors, https://github.com/zloirock/core-js/blob/858461ea1421a53e4fdca91bcac0922f79a3762b/babel.config.js#L26.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: globalThis is not defined · Issue #2795 - GitHub
global.globalThis = xxx. I use this way to fix this problem on node v.10.x. my enviroment is node v.10.x and there are too...
Read more >
A horrifying globalThis polyfill in universal JavaScript
This write-up describes the difficulties with writing a proper globalThis polyfill. Such a polyfill has the following requirements:.
Read more >
globalThis - JavaScript - MDN Web Docs
The global globalThis property contains the global this value, which is usually akin to the global object.
Read more >
How to polyfill `globalThis` into older browsers? - Stack Overflow
So in theory, it seems like I should be able to polyfill support for this into Chromium 70. At first, I took a...
Read more >
core-js | Yarn - Package Manager
Object#__(define|lookup)[GS]etter__. Remove obsolete features: Error.isError (withdrawn); System.global and global (replaced by globalThis ); Map#toJSON and Set ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found