springboot- react应用程序在Internet Explorer 11和9中不起作用

时间:2019-08-09 18:39:56

标签: reactjs spring-boot internet-explorer internet-explorer-11 internet-explorer-9

我的react应用程序无法在Internet Explorer 11上运行。在边缘和Chrome上运行正常。 当我通过Node.js连接应用程序时,react build文件夹可以正常运行IE 11和9。通过节点服务器端口可以正常运行。

现在我正在使用Spring Boot,但在IE11和9中无法正常工作。 我已经在IIS中部署了我的react应用。

我已经通过 npx create-react-app 创建了我的应用程序。(如其他答案中针对类似问题所指出的那样)

我已经在我的两个index.js文件中都包含了此文件,但是它不起作用。 并在我的应用https://www.npmjs.com/package/react-app-polyfill

中安装了polyfill
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/ie11';   

这是我得到的错误: enter image description here

我查看了链接,他们也遇到了相同的错误,他尚未批准任何答案React app not working in Internet Explorer 11 这是我的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",
        "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 :(得分:1)

根据https://www.npmjs.com/package/react-app-polyfill的建议:

  

如果要支持Internet Explorer 9或Internet Explorer 11,则应同时包含ie9或ie11和稳定模块

在主js文件中

import react-app-polyfill的 stable 模块

import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';

ie11也应包含在您的浏览器列表中:

  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all",
      "ie 11"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version",
      "ie 11"
    ]
  }

答案 1 :(得分:0)

什么对我的开发和生产都有效

1。导入polyfills https://www.npmjs.com/package/react-app-polyfill#polyfilling-other-language-features

import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';

2。将ie11 / ie9包含在package.json https://github.com/browserslist/browserslist

中的浏览器列表中
"browserslist": {
"production": [
  ">0.2%",
  "not dead",
  "not op_mini all",
  "ie 11"
],
"development": [
  "last 1 chrome version",
  "last 1 firefox version",
  "last 1 safari version",
  "ie 11"
]

}

3。从node_modules https://create-react-app.dev/docs/supported-browsers-features/#supported-browsers中删除.cache文件夹(这是开发环境的窍门)