babel-loader和webpack版本不一致,導致項目啓動失敗

使用create-react-app腳手架創建好一個項目之後,我的項目名稱是my-react,在項目下使用npm start啓動程序,但是在這一步出現錯誤

意思是說用create-react-app創建項目的時候所用到的babel-loader依賴是8.0.6版本的,但是在我所創建項目的node_modules下的babel-loader版本是7.1.5的版本。所以我要把版本升級纔可以啓動項目。

其實解決辦法其實圖上已經給出1-7點

  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 "babel-loader" 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:
  5. 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.
  6. Check if /Users/amy/Projects/HandheldWestLake/node_modules/babel-loader is outside your project directory.
    For example, you might have accidentally installed something in your home folder.
  7. Try running npm ls babel-loader in your project folder.
    This will tell you which other package (apart from the expected react-scripts) installed babel-loader.

我在發生錯誤之後我也搜索到相關的問題了,看到了解決辦法如下:

但是結合自己的文件整理出來瞭如下幾個步驟:

1.刪除package-lock.json文件

2.刪除你文件夾中的node_modules模塊

3.卸載package.json文件中的babel-loader 即npm uninstall babel-loader

4.安裝你用到的版本 npm install [email protected]的需要的是8.0.6。

但是我還是建議直接安裝你所需要的版本,也就是第四步。

這裏我們所注意的地方就是要按照錯誤信息提供的地址來進行安裝版本。

我的是如下圖:這裏進行安裝的地方並不是我們項目的地址。

以上就是這些問題。弄好後直接啓動項目即可。 

babel-loder的問題剛解決,隨後webpack也報了同樣的問題

解決辦法是一樣的直接安裝所需的版本就可以了

npm i -D [email protected]

 那麼這樣所有的問題都解決了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章