【问题标题】:React app not working in Internet Explorer 11React 应用程序在 Internet Explorer 11 中不起作用
【发布时间】:2019-10-18 15:47:15
【问题描述】:

我的 React 应用无法在 Internet Explorer 11 上运行。它在 edge 和 chrome 上运行良好。

我已经创建了很多文件,但我认为我不能尝试 npx create-react-app。(正如在其他类似问题的答案中指出的那样)

我已将它包含在我的两个 index.js 文件中,但它不起作用。

import 'react-app-polyfill/ie11';

这是我得到的错误:

我查看了链接,他们要求解决括号错误,但当我看到代码时没有问题。

这是我的 package.json 文件:

{
      "name": "insurance_automation",
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "axios": "^0.18.0",
        "babel-polyfill": "^6.26.0",
        "bcryptjs": "^2.4.3",
        "body-parser": "^1.19.0",
        "config": "^3.1.0",
        "cors": "^2.8.5",
        "express": "^4.17.1",
        "jsonwebtoken": "^8.5.1",
        "multer": "^1.4.1",
        "mysql2": "^1.6.5",
        "node": "^11.15.0",
        "nodemailer": "^6.2.1",
        "react": "^16.8.6",
        "react-dom": "^16.8.6",
        "react-router-dom": "^5.0.0",
        "react-scripts": "3.0.1",
        "sequelize": "^5.8.6",
        "universal-cookie": "^4.0.0"
      },
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject",
        "server": "nodemon server",
        "dev": "concurrently \"npm run server\" \"npm start\" "
      },
      "eslintConfig": {
        "extends": "react-app"
      },
      "browserslist": {
        "production": [
          ">0.2%",
          "not dead",
          "not op_mini all"
        ],
        "development": [
          "last 1 chrome version",
          "last 1 firefox version",
          "last 1 safari version"
        ]
      },
      "devDependencies": {
        "concurrently": "^4.1.0",
        "nodemon": "^1.19.1"
      }
    }

【问题讨论】:

  • 你有安装任何特殊的 npm 包吗?我也遇到了这个问题,在某个时间点我发现它是由错误的转译 npm 包引起的。
  • 我已经包含了我的 package.json 文件,那里有任何可疑的依赖关系吗?
  • 尝试参考此链接可能会帮助您了解问题,并且您可以获得有关可能解决方案的信息。参考:gitmemory.com/issue/facebook/create-react-app/6924/487331305
  • @sachinkalekar 我确实看到了该帖子,但它使用与答案相同的方法。我将尝试单独导入文件。

标签: node.js reactjs internet-explorer


【解决方案1】:

这对我有用。

更新 package.json 中的开发数组

    "development": [
      "ie 11",
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }

在 src 文件夹的 index.js 中添加以下代码

// These must be the first lines in src/index.js
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';

然后删除node_modules文件夹并运行

npm install

IE 默认不支持很多 ES6+ 特性。更多信息,请参考the create-react-app polyfill docs

【讨论】:

  • 不需要import 'react-app-polyfill/stable',其余答案已修复。
  • 我必须添加 import 'react-app-polyfill/stable' 然后它才起作用:) 谢谢!
  • 我还设法使用import 'react-app-polyfill/stable' 让它工作,但我无法让它在应用程序的已发布版本上工作。任何想法
猜你喜欢
  • 2019-12-17
  • 1970-01-01
  • 2016-10-20
  • 2019-08-12
  • 2014-08-22
  • 1970-01-01
  • 1970-01-01
  • 2015-03-22
  • 2018-01-17
相关资源
最近更新 更多