为什么 React npm start 为 webpack-dev-server 3.11.1 返回错误? [英] Why React npm start return error for webpack-dev-server 3.11.1?

查看:144
本文介绍了为什么 React npm start 为 webpack-dev-server 3.11.1 返回错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 React 应用程序中的 npm start 出现以下错误:

I have the following error with npm start in my React application:

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

  "webpack-dev-server": "3.11.1"

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

  C:\Users\Username\node_modules\webpack-dev-server (version: 3.11.0)

通常我通过运行以下代码来解决此类问题:npm install react-scripts@latest.

Usually I fixed this type of issue by running the following code: npm install react-scripts@latest.

但是现在好像 React 还没有更新到最新的 webpack-dev-server

But now it seems like that React is not updated yet to the latest webpack-dev-server

现在的问题是如何解决这个问题.顺便说一句,我在我的项目中使用了 npx create-react-app,谢谢!

Now the question is how to fix that. By the way, I use npx create-react-app for my project, Thanks!

推荐答案

首先,删除 node_modules 文件夹和 yarn-lockpackage-lock.json 文件.

First, remove the node_modules folder and yarn-lock or package-lock.json file.

然后,在您的 .env 文件中添加这一行:

And, then add this line in your .env file:

SKIP_PREFLIGHT_CHECK=true

现在您可以在重新安装软件包后执行 npm startyarn start.它应该可以工作.

Now you can do npm start or yarn start after re-installing the packages. It should work.

说明:

由于某些原因,您在项目的 node_modules 中安装了两个版本的 webpack-dev-server.通过在 .env 文件中设置 SKIP_PREFLIGHT_CHECK=true,我们告诉 npm 忽略此类版本问题.

For some reasons, you have two versions of webpack-dev-server installed in your project's node_modules. By setting SKIP_PREFLIGHT_CHECK=true in .env file, we are telling npm to ignore such version issues.

这篇关于为什么 React npm start 为 webpack-dev-server 3.11.1 返回错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆