reactjs - 安装后新的 React 应用程序无法立即编译
问题描述
我使用 React Native 已经有一段时间了,但我想我会在 Web 上试用 React。所以我遵循了这个指南:https ://reactjs.org/docs/create-a-new-react-app.html但是在使用之后npx create-react-app react-try
,导航到新文件夹,然后输入yarn start
我收到这个错误消息:
Failed to compile.
./src/index.js 1:60
Module parse failed: Unexpected token (1:60)
File was processed with these loaders:
* ./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
* ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
> $RefreshRuntime$ = require('C:/Users/e096752/Documents/Cole's Git Repos/react-try/node_modules/react-refresh/runtime.js');
| $RefreshSetup$(module.id);
这是 create 方法中包含的所有内容: 项目
包.json
{
"name": "react-try",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.2",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
如果您需要任何其他信息,请告诉我。我到底需要做什么?
解决方案
react-scripts 4.0.2 似乎有问题。一种解决方法是在 package.json 上手动将版本更改为 4.0.1,然后运行yarn install
. 这样就行了!
推荐阅读
- prismic.io - 有没有办法将数据发送到 prismic.io?
- mysql - 如何为这种输出/问题创建 mysql 语法
- java - 在java中生成6位pin
- unit-testing - 我应该什么时候在安装了 Flask 的 Dockerfile 中执行单元测试和集成测试?
- android - 为什么 tess-two 显示的结果与 tesseract for windows(由 UB Mannheim 提供)对于同一图像显示不同的结果?
- sql - 如何在纯sql中计算工作日数
- ubuntu-18.04 - 如何在 ubuntu 18.04 服务器中自动登录
- visual-studio - 如何在 Visual Studio 2019 中为窗口窗体应用程序创建 setup.exe 文件?
- php - 如何在 woocommerce 订单列表中显示客户角色列?
- json - 使用 kotlinx.serialization 解析空对象