3

i have installed webpack with below command

yarn add webpack --dev

and after i ran yarn start command inside my react app folder

D:\Workspace\fuel-man-ui\fuel-man-ui>yarn start

Getting below error.

yarn run v1.19.0 $ 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.29.6"

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:

D:\Workspace\fuel-man-ui\fuel-man-ui\node_modules\webpack (version: 4.41.0)

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.

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 D:\Workspace\fuel-man-ui\fuel-man-ui\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!

error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

i have deleted node_modules from my project and devdependencies, also i have removed global node_modules and cache. still getting same error.

I ran npm ls webpack and got below tree

fuel-man-ui@0.1.0 D:\Workspace\fuel-man-ui\fuel-man-ui
+-- react-scripts@3.0.1
| `-- webpack@4.29.6
|   `-- webpack@4.41.0  extraneous
`-- webpack@4.41.0

npm ERR! extraneous: webpack@4.41.0 D:\Workspace\fuel-man-ui\fuel-man-ui\node_modules\react-scripts\node_modules\webpack\node_modules\webpack
pappu_kutty
  • 2,378
  • 8
  • 49
  • 93
  • From the logs you're using `create-react-app`, which comes bundled with webpack.. why do you want to add..webpack? It literally gives you the reason in the logs if you read it: 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: – bamtheboozle Oct 04 '19 at 09:21
  • no webpack was not there, my css modules are not working without webpack – pappu_kutty Oct 04 '19 at 09:25
  • 1
    webpack is auto installed since you used create-react-app.. – bamtheboozle Oct 04 '19 at 09:31
  • do i need to add webpack in devdependency, to make css modules work? – pappu_kutty Oct 04 '19 at 09:38
  • https://create-react-app.dev/docs/adding-a-css-modules-stylesheet – bamtheboozle Oct 04 '19 at 10:01
  • @DragoşPaulMarinescu, i am just following same steps described here https://stackoverflow.com/questions/50234890/how-to-use-css-modules-with-create-react-app – pappu_kutty Oct 04 '19 at 10:07
  • It literally says "Don't try to install it manually" in the error – Dominic Oct 04 '19 at 10:59
  • @Dominic yes true... i have removed my manual install, i have followed your link, my css modules are working now... – pappu_kutty Oct 04 '19 at 13:02
  • Does this answer your question? [NPM start returns error, "There might be a problem with the project dependency tree"](https://stackoverflow.com/questions/56528222/npm-start-returns-error-there-might-be-a-problem-with-the-project-dependency-t) – Henke Mar 18 '22 at 14:55

4 Answers4

3

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

"webpack": "4.29.6"

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:

In project root delete node_modules and yarn.lock. In package.json remove webpack from the dependencies and run yarn again.

If you want to modify webpack.config for this project you can run yarn eject from here on you are responsible for the webpack.config so it will be harder to update react scripts.

If you don't want to be responsible for the webpack.config you could try to use react-app-rewired an article on this is here

HMR
  • 37,593
  • 24
  • 91
  • 160
  • you mean the webpack is default installed? no need to install webpack explicitly.but my css modules are not working..with default webpack installed – pappu_kutty Oct 04 '19 at 09:34
  • @pappu_kutty If you only want to add a module you can use rewire to add the module to the rewire config. – HMR Oct 04 '19 at 09:40
  • my css modules are not working.. i was told to add webpack dependency to make it work... probably i should work with default dependency suggested by Dragos – pappu_kutty Oct 04 '19 at 09:50
  • @pappu_kutty That would be the easiest solution. But if you really need to modify webpack.config you can opt for react-app-rewired before ejecting the config. – HMR Oct 04 '19 at 09:59
  • what is ejecting the config.. you mean default webpack config. which i replace with custom webpack? – pappu_kutty Oct 04 '19 at 10:08
  • @pappu_kutty link in the answer `yarn eject`. This is quite a bad thing to do because now you're responsible for webpack and can't update react-scripts anymore. Before ejecting you should try if react-app-rewind can do what you need. – HMR Oct 04 '19 at 10:18
  • 1
    i am just going with default webpack config... i am following this post https://stackoverflow.com/questions/50234890/how-to-use-css-modules-with-create-react-app – pappu_kutty Oct 04 '19 at 10:36
1

You should create .env file in the root (not inside src folder) and add SKIP_PREFLIGHT_CHECK=true Then you can use yarn start or npm start. It works!

Ryan Dhungel
  • 3,637
  • 4
  • 19
  • 26
0

Yesterday I had the same issue. In my case it turned out, that I had two installations of node (one using brew, one using downloaded dmg file). It helped when I removed the one installed via brew.

pidabrow
  • 966
  • 1
  • 21
  • 47
0

The file .env with added SKIP_PREFLIGHT_CHECK=true