【发布时间】: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();
【问题讨论】: