【问题标题】:Using create-react-app by default does not work for IE edge默认情况下使用 create-react-app 不适用于 IE edge
【发布时间】:2020-01-09 10:16:55
【问题描述】:

创建反应应用:

npx create-react-app --name=helloworld --use-npm

然后我加载示例

npm start

在 chrome 和 IE edge 中访问 localhost:3000 的浏览器。

  • 预期:查看 vanilla react 应用程序
  • 实际:白屏,语法错误

除了上述之外,我还尝试了以下方法,但仍然无法正常工作:

package.json

{
  "name": "helloworld",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@babel/polyfill": "^7.7.0",
    "@babel/preset-env": "^7.7.7",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.0",
    "@testing-library/user-event": "^7.2.1",
    "core-js": "^3.6.2",
    "react": "^16.12.0",
    "react-app-polyfill": "^1.0.5",
    "react-dom": "^16.12.0",
    "react-scripts": "3.3.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      "defaults",
      "ie 10"
    ],
    "development": [
      "defaults",
      "ie 10"
    ]
  }
}

.babelrc

{
    "presets": [
        [
"@babel/preset-env", {
      "useBuiltIns": "entry",
            "debug":true
        }]
    ]
}

index.js

import '@babel/polyfill';
import 'core-js';
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';
import 'react-app-polyfill/ie11';

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(<App />, document.getElementById('root'));
serviceWorker.unregister();

【问题讨论】:

    标签: babeljs create-react-app


    【解决方案1】:

    好的,这是我发现的一个错误,如 github 中所示。目前这是一个 hacky 解决方案,但这很有效。 - https://github.com/facebook/create-react-app/issues/8084

    • ./node_modules/react-dev-utils/webpackHotDevClient.js:60 添加斜杠:true

    示例:

    var connection = new WebSocket(
      url.format({
        protocol: 'ws',
        hostname: window.location.hostname,
        port: window.location.port,
        // Hardcoded in WebpackDevServer
        pathname: '/sockjs-node',
        slashes: true
      })
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 2021-05-14
      • 2018-04-02
      • 2016-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多