我无法使用 npm start 运行反应应用程序如何解决此错误?
Posted
技术标签:
【中文标题】我无法使用 npm start 运行反应应用程序如何解决此错误?【英文标题】:i can't run react app using npm start how to fix this error? 【发布时间】:2021-08-20 22:33:04 【问题描述】:Failed to compile
./src/index.js 1:39 模块解析失败:意外令牌 (1:39) 使用这些加载器处理了文件:
./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js ./node_modules/babel-loader/lib/index.js 您可能需要额外的加载器来处理这些加载器的结果。$RefreshRuntime$ = require('C:/Users/I'm-cx0140/Desktop/dreact/node_modules/react-refresh/runtime.js'); | $RefreshSetup$(module.id); | 此错误发生在构建期间,无法关闭
我的 package.json
"name": "myapp",
"version": "0.1.0",
"private": true,
"dependencies":
"@testing-library/jest-dom": "^5.13.0",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.2"
,
"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"
]
enter code here
"name": "myapp",
"version": "0.1.0",
"private": true,
"dependencies":
"@testing-library/jest-dom": "^5.13.0",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.2"
,
"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"
]
【问题讨论】:
您介意发布您的 Babel 配置吗?或者这是一个 create-react-app 应用程序?如果没有,您可能需要配置@babel/preset-react
和 @babel/preset-env
。
请添加您的配置文件。像 package.json、babel config、
我只有 package.json 而不是 babel 配置
【参考方案1】:
您的用户名(I'm-cx0140)中的 ' 字符可能会触发此问题,请在另一个文件夹中创建您的项目。
【讨论】:
以上是关于我无法使用 npm start 运行反应应用程序如何解决此错误?的主要内容,如果未能解决你的问题,请参考以下文章
简单的反应适用于 npm start 但不适用于 nohup npm start &
在我的反应 js 项目中运行 npm start 时出现白屏
创建反应应用程序时使用 babel 的 npm start(或 yarn start)错误