Skip to content
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

Iterator cannot be polyfilled in Safari (up to 18) #1390

Closed
CreativeTechGuy opened this issue Feb 4, 2025 · 9 comments
Closed

Iterator cannot be polyfilled in Safari (up to 18) #1390

CreativeTechGuy opened this issue Feb 4, 2025 · 9 comments

Comments

@CreativeTechGuy
Copy link

When using a polyfill which depends on Iterator such as

const m = new Map();
m.keys().map(() => {}); // <- `.map` is from the Iterator protocol

As of Safari 18, it doesn't support most of the Iterator protocol. But the polyfill attempts to augment the globalThis["Iterator"] prototype, which doesn't exist in Safari (despite the compat chart saying it should). So the polyfill despite being loaded doesn't initialize and no-op.

I don't know if there is any way that this can be fixed in core-js so that these Iterator polyfills work in Safari. At the very least I hope this issue will help others not run into this.

@zloirock
Copy link
Owner

zloirock commented Feb 4, 2025

core-js is being tested in Safari 18 in CI and regularly manually, and everything works fine.

Image

That could happen if for any reason you missed the import of es.iterator.constructor module.

@zloirock
Copy link
Owner

zloirock commented Feb 4, 2025

You could report it here https://github.com/babel/babel-polyfills

Current definitions here look fine, as an option - you use an obsolete @babel/preset-env / babel-plugin-polyfill-corejs3 version.

@zloirock zloirock closed this as completed Feb 4, 2025
@CreativeTechGuy
Copy link
Author

Actually, I just double checked and @babel/preset-env is showing that esnext.iterator.constructor is being included along with esnext.iterator.map. I was only stepping through the iterator map polyfill to see why it might not be working, but now I'll step through the iterator constructor polyfill to see why it might not be doing anything.

@zloirock zloirock reopened this Feb 4, 2025
@zloirock
Copy link
Owner

zloirock commented Feb 4, 2025

Actually, I just double checked and @babel/preset-env is showing that esnext.iterator.constructor is being included along with esnext.iterator.map. I was only stepping through the iterator map polyfill to see why it might not be working, but now I'll step through the iterator constructor polyfill to see why it might not be doing anything.

In this case, please, add a reproducible example.

@CreativeTechGuy
Copy link
Author

And I just checked versions and I'm using [email protected] and @babel/[email protected], so not the latest, but pretty close.

And yes I'll get a minimal reproducible example for you later today. Thank you so much for your help and all of the work you do!

@zloirock
Copy link
Owner

zloirock commented Feb 4, 2025

babel-plugin-polyfill-corejs3 had a related issue in definitions that was fixed recently, babel/babel-polyfills#223, so make sure that you use the latest versions of all those packages.

@CreativeTechGuy
Copy link
Author

Repro is here: https://github.com/CreativeTechGuy/core-js-safari-iterator-repro

Let me know if there's anything else I can do to make this easier. I tried to use the very least amount of config/code/dependencies to make it super straight forward.

@zloirock
Copy link
Owner

zloirock commented Feb 7, 2025

@CreativeTechGuy your example contains [email protected] with the mentioned related bug. It was fixed in 0.11.0. It seems it is still not updated in the published @babel/preset-env. You could ask for it in their repo.

@CreativeTechGuy
Copy link
Author

Thank you! It's always frustrating when a new version that fixes a problem is released but not yet consumed where it's used. I'll go ask for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants