本文介绍了对象不支持属性或方法“条目"-IE11中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用create-react-app引导的React应用,它在Chrome中完美运行,但无法在IE11中运行.

I am working on a react app bootstrapped using create-react-app and it works perfectly in Chrome but I cannot get it to work in IE11.

启动应用程序后,我从控制台收到以下错误:

Upon launching the app, I am getting the following error from the console:

Object doesn't support property or method 'entries'

我花了数小时拖拉Google试图寻找解决方案,但没有一个推荐的解决方案.

I have spent hours trawling Google trying to find a solution and none of the recommended ones work.

我尝试过的事情:

  • index.js顶部导入react-app-polyfill/ie11react-app-polyfill/stable
  • index.js顶部导入core-js/es/object/entriescore-js/features/object/entries
  • index.js :
  • importing react-app-polyfill/ie11 and react-app-polyfill/stable at the top of index.js
  • importing core-js/es/object/entries and core-js/features/object/entries at the top of index.js
  • 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"
    ]
  }
}

参考:

  • https://github.com/facebook/create-react-app/issues/8405
  • Best way to polyfill ES6 features in React app that uses create-react-app

推荐答案

您可以降级您的react-scripts版本.在您的package.json中,将其更改为"react-scripts":"3.2.0".

You can downgrade your react-scripts version.In your package.json , alter to "react-scripts": "3.2.0".

看看 https://github.com/facebook/create -react-app/issues/8405 .

这篇关于对象不支持属性或方法“条目"-IE11中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 01:31
查看更多