Javascript React JS 不适用于 Internet Explorer 9

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29828561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:05:05  来源:igfitidea点击:

React JS not working with Internet Explorer 9

javascriptinternet-explorer-9reactjs

提问by user1620122

I'm trying to use React with Internet Explorer 9 but getting the following errors even trying to run something very barebones:

我正在尝试将 React 与 Internet Explorer 9 一起使用,但即使尝试运行一些非常简单的东西,也会收到以下错误:

SCRIPT438: Object doesn't support property or method 'isArray' react-with-addons.js, line 4 character 317

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

SCRIPT438: Object doesn't support property or method 'create' JSXTransformer.js, line 4 character 326

SCRIPT438:对象不支持属性或方法“创建”JSXTransformer.js,第 4 行字符 326

I've read https://facebook.github.io/react/docs/working-with-the-browser.html, which says IE8 might have these issues, but no mention about IE9. Googling didn't really bring up any solutions either.

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

Still, I tried adding es5-shim/sham as suggested on that page. That results in a different error:

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

SCRIPT438: Object doesn't support property or method 'hasAttribute' es5-shim.min.js, line 6 character 4143

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

Has anyone encountered these errors before in IE9 or otherwise?

有没有人在 IE9 或其他情况下遇到过这些错误?

Thanks for the help!

谢谢您的帮助!

The full code I'm trying to run is:

我试图运行的完整代码是:

<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>

回答by monastic-panic

Generally, you need to include the specified polyfills for ES5 features (as you've noticed): https://facebook.github.io/react/docs/react-dom.html#browser-support

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

You may also need HTML5 Shiv in addition to the the polyfills you've provided.

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

More specifically, though, the problem is probably not with polyfills but with the document mode IE9 is running in. You want to make sure that you are setting the correct document mode in your HTML file so IE knows which version to target. Otherwise, even though you are using IE9 it may be targeting IE7 which is no good.

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

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

回答by Manjula Devi

In index.js file you have to add polyfill. These imports should be in the first of your import.

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

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

Now open in ur ie it works.

现在在 ur 中打开它可以工作。

Before import you have to install react-app-polyfill.

在导入之前,您必须安装 react-app-polyfill。

 //To install use below command:

 npm install react-app-polyfill

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

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