1. 程式人生 > >解決create-react-app 後 npm start 中出現 的webpack版本問題和webpack-dev-server的版本問題

解決create-react-app 後 npm start 中出現 的webpack版本問題和webpack-dev-server的版本問題

利用VSCode搭建react的腳手架執行環境的時候。create-react-app之後npm 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\17720\node_modules\webpack (version: 4.25.1)
(version: 2.9.1) Manually installing incompatible versions is known to cause hard-to-debug issues.

在參考 https://blog.csdn.net/muzi190/article/details/84108714 之後,又出現如下的問題。。。:

PS C:\Users\17720\Desktop\Study\React\hello> npm start

> [email protected] start C:\Users\17720\Desktop\Study\React\hello
> 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-dev-server": "3.1.14" 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\17720\node_modules\webpack-dev-server (version: 2.9.1) Manually installing incompatible versions is known to cause hard-to-debug issues.

解決辦法:找到版本出問題的目錄:如我的是

C:\Users\17720\node_modules\

然後在該路徑(這是全域性路徑)下解除安裝不符合版本的webpack 與 webpack-dev-server

注意解除安裝webpack時還需要解除安裝webpack-cli ,4.0版本後的webpack都帶有webpack-cli:

npm un webpack
npm un webpack-cli
npm un webpack-dev-server

然後再把提示報錯的版本安裝上,如:

npm i [email protected]
npm i webpack-cli
npm i webpack[email protected]

這時候再次npm start 就沒出現問題啦