对象不支持 属性 或方法 'entries' - IE11 中的错误
Object doesn't support property or method 'entries' - error in IE11
我正在开发一个使用 create-react-app 引导的 React 应用程序,它在 Chrome 中完美运行,但我无法在 IE11 中运行它。
启动应用程序后,我从控制台收到以下错误消息:
Object doesn't support property or method 'entries'
我花了几个小时搜索 Google 试图找到解决方案,none 推荐的解决方案有效。
我尝试过的东西:
- 在
index.js
的顶部导入 react-app-polyfill/ie11
和 react-app-polyfill/stable
- 在
index.js
的顶部导入 core-js/es/object/entries
和 core-js/features/object/entries
- Adding the following to
index.js
:
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;
};
}
package.json:
{
"name": "ceas-ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"auth0-js": "^9.8.2",
"bootstrap": "^4.1.3",
"core-js": "^3.6.4",
"env-cmd": "^8.0.2",
"joi-browser": "^13.4.0",
"react": "^16.12.0",
"react-app-polyfill": "^1.0.6",
"react-bootstrap": "^1.0.0-beta.16",
"react-dom": "^16.12.0",
"react-loader-spinner": "^2.3.0",
"react-modal": "^3.8.1",
"react-router-bootstrap": "^0.25.0",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.3.1",
"react-slidedown": "^2.4.5",
"react-toastify": "^4.5.2",
"styled-components": "^5.0.0"
},
"scripts": {
"start": "react-scripts start",
"test": "cls && react-scripts test --coverage --env=jsdom",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browser": {
"joi": "joi-browser"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"chai": "^4.2.0",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.9.0",
"jsdom": "^13.2.0",
"mocha": "^6.0.0",
"react-test-renderer": "^16.8.2",
"rimraf": "^2.6.3"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all",
"ie 11"
],
"development": [
">0.2%",
"not dead",
"not op_mini all",
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version",
"ie 11"
]
}
}
参考文献:
您可以降级您的 react-scripts 版本。
在您的 package.json 中,更改为 "react-scripts": "3.2.0".
这似乎是 react-scripts
3.3.0 及更高版本的问题。您可以在 GitHub 中找到许多问题报告,例如:github.com/facebook/create-react-app/issues/8197, github.com/facebook/create-react-app/issues/8195.
它仍然可以与 react-scripts@3.2.0
一起使用。作为解决方法,您可以尝试恢复到 3.2.0。还请记得删除 node_modules
中的 .cache
文件夹并删除 IE 浏览器缓存,然后重试。
我正在开发一个使用 create-react-app 引导的 React 应用程序,它在 Chrome 中完美运行,但我无法在 IE11 中运行它。
启动应用程序后,我从控制台收到以下错误消息:
Object doesn't support property or method 'entries'
我花了几个小时搜索 Google 试图找到解决方案,none 推荐的解决方案有效。
我尝试过的东西:
- 在
index.js
的顶部导入 - 在
index.js
的顶部导入 - Adding the following to
index.js
:
react-app-polyfill/ie11
和 react-app-polyfill/stable
core-js/es/object/entries
和 core-js/features/object/entries
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;
};
}
package.json:
{
"name": "ceas-ui",
"version": "0.1.0",
"private": true,
"dependencies": {
"auth0-js": "^9.8.2",
"bootstrap": "^4.1.3",
"core-js": "^3.6.4",
"env-cmd": "^8.0.2",
"joi-browser": "^13.4.0",
"react": "^16.12.0",
"react-app-polyfill": "^1.0.6",
"react-bootstrap": "^1.0.0-beta.16",
"react-dom": "^16.12.0",
"react-loader-spinner": "^2.3.0",
"react-modal": "^3.8.1",
"react-router-bootstrap": "^0.25.0",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.3.1",
"react-slidedown": "^2.4.5",
"react-toastify": "^4.5.2",
"styled-components": "^5.0.0"
},
"scripts": {
"start": "react-scripts start",
"test": "cls && react-scripts test --coverage --env=jsdom",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browser": {
"joi": "joi-browser"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"chai": "^4.2.0",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.9.0",
"jsdom": "^13.2.0",
"mocha": "^6.0.0",
"react-test-renderer": "^16.8.2",
"rimraf": "^2.6.3"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all",
"ie 11"
],
"development": [
">0.2%",
"not dead",
"not op_mini all",
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version",
"ie 11"
]
}
}
参考文献:
您可以降级您的 react-scripts 版本。 在您的 package.json 中,更改为 "react-scripts": "3.2.0".
这似乎是 react-scripts
3.3.0 及更高版本的问题。您可以在 GitHub 中找到许多问题报告,例如:github.com/facebook/create-react-app/issues/8197, github.com/facebook/create-react-app/issues/8195.
它仍然可以与 react-scripts@3.2.0
一起使用。作为解决方法,您可以尝试恢复到 3.2.0。还请记得删除 node_modules
中的 .cache
文件夹并删除 IE 浏览器缓存,然后重试。