babel-loader版本不一致報錯

在做項目的時候出現(xiàn)一個問題,由于babel-loader版本號不一致報錯,報錯如下圖:

圖中說:用create-react-app創(chuàng)建項目的時候所用到的babel-loader依賴是8.04版本,但是在我創(chuàng)建項目的node_modules下的babel-loader版本是8.0.5版本的.
npm報錯.png

結(jié)果打開pakage.json和package-lock.json文件果然babel-loader版本不一樣


json.png
lock.png
解決辦法其實第一張圖已經(jīng)給出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.
但是結(jié)合自己的文件整理出來了如下幾個步驟:
1.刪除package-lock.json文件
2.刪除你文件夾中的node_modules模塊
3.卸載package.json文件中的babel-loader 即npm uninstall babel-loader
4.安裝你用到的版本 npm install babel-loader@8.04我的需要的是8.04
5.npm start啟動項目
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容