React JS 不适用于 Internet Explorer 9

React JS not working with Internet Explorer 9

我正在尝试将 React 与 Internet Explorer 9 一起使用,但即使尝试 运行 一些非常准系统的东西也会出现以下错误:

SCRIPT438:对象不支持 属性 或方法 'isArray' react-with-addons.js,第 4 行字符 317

SCRIPT438:对象不支持 属性 或方法 'create' JSXTransformer.js, 第 4 行字符 326

我读过 https://facebook.github.io/react/docs/working-with-the-browser.html,它说 IE8 可能有这些问题,但没有提到 IE9。谷歌搜索也没有真正提出任何解决方案。

不过,我尝试按照该页面上的建议添加 es5-shim/sham。这会导致不同的错误:

SCRIPT438:对象不支持 属性 或方法 'hasAttribute' es5-shim.min.js, 第 6 行字符 4143

有没有人以前在 IE9 或其他方面遇到过这些错误?

感谢您的帮助!

我正在尝试 运行 的完整代码是:

<html>

<head>
  <script src="js/es5-shim.min.js"></script>
  <script src="js/es5-sham.min.js"></script>
  <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
  <script src="js/react-with-addons.js"></script>
  <script src="js/JSXTransformer.js"></script>

</head>

<body>
  <div id="container"></div>
  <script type="text/jsx">
    React.render(
    <h1>HELLO WORLD!</h1>
    );
  </script>
</body>

</html>

通常,您需要为 ES5 功能包含指定的 polyfill(如您所见):https://facebook.github.io/react/docs/react-dom.html#browser-support

除了您提供的 polyfill 之外,您可能还需要 HTML5 Shiv。

不过,更具体地说,问题可能不是 polyfill,而是 IE9 的文档模式 运行。您要确保在 HTML 中设置正确的文档模式] 文件,以便 IE 知道要定位哪个版本。否则,即使您使用的是 IE9,它也可能针对 IE7,这并不好。

<meta http-equiv="X-UA-Compatible" content="IE=edge">

在 index.js 文件中,您必须添加 polyfill。这些导入应该在您导入的第一个。

import 'react-app-polyfill/ie9';
import 'react-app-polyfill/ie11';   
//other imports

现在在你的 ie 中打开,它有效。

导入之前你必须安装react-app-polyfill。

 //To install use below command:

 npm install react-app-polyfill

link参考: https://www.npmjs.com/package/react-app-polyfill