IE11:如何在 React 中的 Internet Explorer 中 polyfill `Array.values().next()`?

问题描述

我在 IE11 中运行的 React 项目中遇到迭代器问题。

这是重现问题的最少代码量;

// 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);
...

在 IE11 中,我收到一条错误消息

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

我已经导入了整个 'core-js' 库,我还需要导入什么才能在 IE11 中填充此功能

解决方法

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

作为 index.js 中的前两行 https://www.npmjs.com/package/react-app-polyfill