运行react项目,npm run start/build, 报错 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.

如题:这个问题困扰了我半天,网上搜索各种解决方法,都没能解决,最后仔细读一遍原因才发现问题很简单,就是版本不一致

  为啥不一样,哪里有两个相同的依赖呢,请看下文:

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"

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

  E:\company_work\wbwork\zabbix2\node_modules\webpack (version: 3.10.0)

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

报错如上所示,不一定是webpack,还是其他依赖文件版本冲突,如babel-eslint, babel-loader, webpack-dev-server等等,

这个版本冲突是因为react-scripts中重新依赖了一套相同的,坑爹呀,react自行依赖一套了,结果版本不一致导致的。

怎样看你的项目中是否有相同的依赖

npm ls webpack

如上指令,webpack 可以换成任何同样报错的依赖名称即可查询

结果:

$ npm ls webpack
adminstock@0.1.0 E:\GitLab\adminstock\web
+-- react-scripts@3.4.1
| `-- webpack@4.42.0
`-- webpack@4.41.0

看到了吧,react-scripts 还有相同的一套webapck,但是版本不一样。

要怎么改,其实很简单,

在package.json中,找到react-scirpts,将他的版本号前面的 ^ 这个符号删掉,然后重新npm install 一下就可以了

^ 符号标识最新版本,不是指你当前写的版本,大坑呀。

不信的话,你npm install 完,再运行一下

npm ls webpack  检查版本是不是一样

$ npm ls webpack
adminstock@0.1.0 E:\GitLab\adminstock\web
+-- react-scripts@3.2.0
| `-- webpack@4.41.0 deduped
`-- webpack@4.41.0

完美解决, 亲测

运行react项目,npm run start/build, 报错 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.

上一篇:Android常用ADB命令总结


下一篇:移动端适配剖析