简体   繁体   English

React JS 不适用于 Internet Explorer 9

[英]React JS not working with Internet Explorer 9

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.我读过https://facebook.github.io/react/docs/working-with-the-browser.html ,它说 IE8 可能有这些问题,但没有提到 IE9。 Googling didn't really bring up any solutions either.谷歌搜索也没有真正提出任何解决方案。

Still, I tried adding es5-shim/sham as suggested on that page.尽管如此,我还是尝试按照该页面上的建议添加 es5-shim/sham。 That results in a different error:这会导致不同的错误:

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>

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.更具体地说,问题可能不在于 polyfill,而在于 IE9 正在运行的文档模式。您要确保在 HTML 文件中设置了正确的文档模式,以便 IE 知道要定位哪个版本。 Otherwise, even though you are using IE9 it may be targeting IE7 which is no good.否则,即使您使用的是 IE9,它也可能针对 IE7,这是不好的。

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

In index.js file you have to add polyfill.在 index.js 文件中,您必须添加 polyfill。 These imports should be in the first of your import.这些导入应该在您的第一个导入中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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