即使添加Polyfill,获取对象也不支持属性或方法“条目"错误 [英] Getting Object doesn't support property or method 'entries' error even when I am adding polyfill
问题描述
我正在尝试使用package.json中的以下browserslist
配置在IE11上加载我的Web应用程序
I am trying to load my web application on IE11 with the following browserslist
configuration in package.json
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
">0.1%",
"not dead",
"not op_mini all"
]
}
以及src/index.tsx
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';
但是我听到一个错误,说SCRIPT438: Object doesn't support property or method 'entries'
.为了克服这个问题,我阅读了 SO不支持属性或方法的SO帖子,项" ,但不好.
But I get an error saying SCRIPT438: Object doesn't support property or method 'entries'
. To overcome this I read the SO post at Object doesn't support property or method 'entries' but no good.
我尝试安装yarn add core-js
,但是当我尝试执行import 'core-js/es7/object';
时,构建失败,提示该模块不存在.我在这里该怎么办?我想念的是什么?
I tried installing yarn add core-js
but when I try to do import 'core-js/es7/object';
the build fails saying the module does not exist. What should I do here? What is it that I am missing?
推荐答案
我尝试安装yarn add core-js,但是当我尝试导入时 'core-js/es7/object';构建失败说模块没有 存在.我在这里该怎么办?我想念的是什么?
I tried installing yarn add core-js but when I try to do import 'core-js/es7/object'; the build fails saying the module does not exist. What should I do here? What is it that I am missing?
也许该问题与core-js版本有关.在我的react应用程序中,它使用core-js@3.0.1版本,它不包含es7文件夹,并且如果我使用Object.entries()方法,则在IE11中效果很好(不添加polyfill,也许它已经添加对象引用).
Perhaps the issue is related to the core-js version. In my react application, it using core-js@3.0.1 version, it doesn't contain the es7 folder, and if I using the Object.entries() method, it works well in IE11 (not add polyfill, perhaps it already add the object reference).
此外,我还检查了我的另一个应用程序,它使用的是core-js 2.6.1版本,我们可以看到core-js文件夹中包含es7软件包,您还可以检查core-js版本:
Besides, I also checked my another application, it using the core-js 2.6.1 version, and we can see the core-js folder contain es7 package, you could also check the core-js version:
尝试引用此链接以更新core-js版本:
Try to refer this link to update core-js version:
此外,您还可以在Index.html的标题中添加以下脚本.在IE11浏览器中也可以很好地工作.
Besides, you could also add the following script in the header of Index.html. It also works well in IE11 browser.
<script>
if (!Object.entries) {
Object.entries = function( obj ){
var ownProps = Object.keys( obj ),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--)
resArray[i] = [ownProps[i], obj[ownProps[i]]];
return resArray;
};
}
</script>
这篇关于即使添加Polyfill,获取对象也不支持属性或方法“条目"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!