Why React npm start return error for webpack-dev-server 3.11.1?

Viewed 2279

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)

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

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

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

3 Answers

I have write following commands in react project Open project in command prompt

  1. npm uninstall -g webpack-dev-server
  2. remove web-dev-server folder from node_modules(C:/Users/UserName/Node_Modules)
  3. npm i -g webpack-dev-server@3.11.1
  4. remove package-lock.json and write npm install

after it your react project may be start by npm start

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

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

SKIP_PREFLIGHT_CHECK=true

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

Explanation:

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.

Check if node_modules and package-lock.json are present in your home folder, instead of your project folder. If yes, delete those two folders and then go for npm start.

Related