react报错解决

报错分析

阅读报错信息不难发现,是说您用 create-react-app 命令创建项目时所用到的 babel-loader 依赖为 8.1.0 版本,但您项目下 node_modules 包下的 babel-loader 版本为 8.0.6

所以导致 版本冲突 无法启动项目问题,报错信息中,React 其实已经给出了解决方案。

bash 复制代码
## SEO

There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

  "babel-loader": "8.1.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-loader was detected higher up in the tree:

  C:\Users\Flutter\node_modules\babel-loader (version: 8.0.6)

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

一、解决方案

打开项目文件夹(React工程目录),执行以下步骤:

  1. 删除 package-lock.json 文件。
  2. 删除 node-modules
  3. 删除 babel-loader 模块,执行以下命令:
bash 复制代码
npm uninstall babel-loader
  1. 安装指定版本 babel-loader,执行以下命令:

这里我们所注意的地方就是要按照错误信息提供的地址来进行安装版本,如下图所示:

cd C:\Users\Flutter (没有node_modules),然后再执行下面的安装。

bash 复制代码
## 版本号要根据你的版本来确定(绿色字)
npm install babel-loader@8.1.0

最后 npm start 启动即可,别忘了 cd 回项目根目录再执行。

可能遇到的问题

我这里刚解决完 babel-loader 后,又出现了 webpack 版本问题,继续解决。

直接 cdC:\Users\Flutter 目录下,直接执行如下命令继续安装:

bash 复制代码
npm i -D webpack@4.42.0

二、解决方案

注意:该方案不适用于 部署上线环境 因为可能出现未知错误。

在项目根目录创建一个 .env 文件,然后添加以下代码:

bash 复制代码
SKIP_PREFLIGHT_check = true

重新 npm start 运行即可解决。

相关推荐
奇奇怪怪的4 分钟前
检索增强——混合检索、Re-rank 与 Query 优化
前端
user62229864925817 分钟前
React 常用技术知识全景:从组件到 Hooks 的系统理解
前端
麻辣凉茶7 分钟前
给阿嬤一封来自云端的信(上)
前端·node.js
前端缘梦9 分钟前
LangGraph 实战:从 0 到 1 构建 AI 代码生成工作流
前端·程序员·全栈
weedsfly9 分钟前
栈和堆:JavaScript 内存的“旅馆”和“仓库”
前端·javascript·面试
用户0595401744610 分钟前
大模型长上下文遗忘排查实录:用 Playwright 自动化测试,揪出了 90% 的存储序列化 bug
前端·css
36304584112 分钟前
Signal 带来的架构问题思考
前端·vue.js
达达尼昂17 分钟前
Claude : 如何设计可控的agent-loops
前端·人工智能·后端
IT_陈寒1 小时前
Redis持久化丢失数据的坑,这次终于被我填平了
前端·人工智能·后端