0
votes

So whenever I run npm start in my React project it gives me this error:

[email protected] start C:\Users\AyaLe\Desktop\React\myapp react-scripts start

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:

"webpack": "4.19.1"

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

C:\Users\AyaLe\node_modules\webpack (version: 3.10.0)

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

If 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.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem. If this has not helped, there are a few other things you can try:

  1. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead. This may help because npm has known issues with package hoisting which may get resolved in future versions.

  2. Check if C:\Users\AyaLe\node_modules\webpack is outside your project directory. For example, you might have accidentally installed something in your home folder.

  3. Try running npm ls webpack in your project folder. This will tell you which other package (apart from the expected react-scripts) installed webpack.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] start: react-scripts start npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR!
C:\Users\AyaLe\AppData\Roaming\npm-cache_logs\2018-12-02T10_15_24_630Z-debug.log

Also whenever I try to install webpack-cli whenever it asks me to, it gives me another error

2
Please include npm and node versions. Maybe a silly question: did you run npm install? A lot of the steps you mentioned are unnecessary. E.g.: 'Remove package-lock.json' because as longs as you do not use npm ci to install dependencies this file is ignored. - GuyT
I've used the create-react-app so that should've taken care installing all the dependencies. This is the package.json : - ayab
{ "name": "my-app", "version": "0.1.0", "private": true, "dependencies": { "react": "^16.6.3", "react-dom": "^16.6.3", "react-scripts": "2.1.1" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": "react-app" }, "browserslist": [ ">0.2%", "not dead", "not ie <= 11", "not op_mini all" ] } - ayab
You may need to manually delete C:\Users\AyaLe\node_modules. By default npm will search parent folders for node_modules which isn't what you want here. - Matt Browne

2 Answers

5
votes

It looks like you have "webpack": "3.10.0" installed globally, but you need to have "webpack": "4.19.1". This is causing a conflict.

You need to do the following:

1. $npm uninstall -g webpack
2. $npm install -g [email protected]

This should solve the issue.

Alternatively, you can try deleting the node_modules folder or specifically the webpack folder in node_modules at the location:

C:\Users\AyaLe\node_modules\webpack (version: 3.10.0)

0
votes

It seems that you have an incorrect version of 'webpack' installed. Check your package.json file to ensure that you have the correct 'webpack' version.

The file should look like something this :

{ 
    ... , 
    "dependencies" : { 
        ..., 
        "webpack" : "<version number>" 
    } 
}

Ensure that the version number is exactly 4.19.1. This will ensure that you install the specific version of webback.

Once you change/update your package.json, try deleting node_modules/ directory and then running npm install in the same directory as your package.json is.