简体   繁体   English

React 应用程序:无法编译。 模块解析失败

[英]React App: Failed to Compile. Module parse failed

在此处输入图片说明

Everytime I create React app and start the development server, I get this error.每次我创建 React 应用程序并启动开发服务器时,都会收到此错误。 HELP!!!帮助!!!

Per this issue, it may be a problem with the react-scripts part of your library.根据问题,您的库的react-scripts部分可能存在问题。 So either use a specific, older version of create react app by running :因此,要么通过运行使用特定的旧版本 create react app:

npx create-react-app@4.0.1 my-app

Or by running CRA as is, then modifying your package.json folder so that the react script version is specified.或者按原样运行 CRA,然后修改您的package.json文件夹,以便指定 react 脚本版本。

So after you run CRA, change your package.json file like so:所以在你运行 CRA 之后,像这样更改你的package.json文件:

{
  "name": "myapp",
  ...
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.0",
    "@testing-library/user-event": "^7.2.1",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-scripts": "4.0.1"           // change this line to 4.0.1
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  ...
}

Then make sure you rm -rf node_modules then run npm install to get a fresh install that removes whatever react-scripts came by default so that you use the specific 4.0.1 version.然后确保您rm -rf node_modules然后运行npm install以获得全新安装,该安装删除默认情况下的任何react-scripts ,以便您使用特定的 4.0.1 版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 编译失败。 找不到模块:无法解析“react-router-dom” - Failed to compile. Module not found: Can't resolve 'react-router-dom' 编译失败。 找不到模块:错误:无法解析 - Failed to compile. Module not found: Error: Can't resolve 编译失败。 ./node_modules/react-dev-utils/formatWebpackMessages.js 模块未找到:无法解析 - Failed to compile. ./node_modules/react-dev-utils/formatWebpackMessages.js Module not found: Can't resolve React App:“模块解析失败:意外令牌” - React App: "Module parse failed: Unexpected token" React App 安装后编译失败 - React App failed to compile after install 反应失败创建反应应用模块未找到 - React failed create react app module not found 为什么会出现此错误 - 无法编译。 无法解析“模块/应用程序”和“来自 chokidar (E:\) 的错误:错误:EBUSY:资源繁忙或锁定”? - Why am I getting this error - Failed to compile. Can't resolve 'modules/App' and "Error from chokidar (E:\): Error: EBUSY: resource busy or locked"? Webpack React 错误:模块解析失败:意外的令牌 - Webpack React error: Module parse failed: Unexpected token create-react-app 编译失败,但进程不会退出 - create-react-app failed to compile, but process won't exit 反应刷卡失败 - react swipe card failed to compile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM