React应用无法在Internet Explorer 11中运行

时间:2019-06-03 05:07:05

标签: node.js reactjs internet-explorer

我的react应用无法在Internet Explorer 11上运行。在边缘和Chrome上运行正常。

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

我已经在我的两个index.js文件中都包含了此文件,但是它不起作用。

import 'react-app-polyfill/ie11';

这是我得到的错误:

This is the error that I am getting:

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

这是我的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"
      }
    }

2 个答案:

答案 0 :(得分:8)

这对我有用。

更新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 +功能。有关更多信息,请参见this

答案 1 :(得分:0)

仅应将其包含在index.js文件中,然后尝试将其导入,这将对您有用。

  

npm install-保存babel-polyfill

将其导入index.js

import 'babel-polyfill';