简体   繁体   中英

IE11: How to polyfill `Array.values().next()` in Internet explorer, in React?

I'm having trouble with iterators in my React project running in IE11.

Here's the minimum amount of code to reproduce the issue;

// index.js

...
import React from 'react'
import ReactDOM from 'react-dom'
import 'core-js'
import 'whatwg-fetch'
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';

const a = [1,2,3,4].values().next();
console.log(a);
...

In IE11, I'm getting an error that says

SCRIPT438: Object doesn't support property or method 'next'

I've already imported the entire 'core-js' library, what else do I need to import to polyfill this functionality in IE11?

put

import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';

as the first two lines in your index.js https://www.npmjs.com/package/react-app-polyfill

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM