创建React应用:
npx create-react-app --name=helloworld --use-npm
然后我加载示例
npm start
在chrome和IE edge中访问位于localhost:3000的浏览器。
除了上述内容外,我还尝试了以下操作,但仍然无法使用:
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();
答案 0 :(得分:1)
好吧,这是我发现的错误,如github中所示。目前,这是一个骇人听闻的解决方案,但是可以。 -https://github.com/facebook/create-react-app/issues/8084
示例:
var connection = new WebSocket(
url.format({
protocol: 'ws',
hostname: window.location.hostname,
port: window.location.port,
// Hardcoded in WebpackDevServer
pathname: '/sockjs-node',
slashes: true
})
);