Error: Cannot find module '@babel/core’

  • 在安裝babel的時(shí)候,遇到個(gè)Error: Cannot find module '@babel/core’問題,查了很多資料才解決,希望能夠幫助到各位兄弟。

問題產(chǎn)生的原因

babel-loader和babel-core版本不對應(yīng)所產(chǎn)生的,

  • babel-loader 8.x對應(yīng)babel-core 7.x
  • babel-loader 7.x對應(yīng)babel-core 6.x

如何解決

1、 卸載舊的babel-core
npm un babel-core
2、 安裝新的babel-core
npm i -D @babel/core
3、 卸載舊的babel-preset
npm un babel-preset-env
npm un babel-preset-stage-0
4、 安裝新的babel-preset
npm i @babel/preset-react
npm i @babel/preset-env
npm i babel-preset-mobx
5、 卸載舊的babel-plugin
npm un babel-plugin-transform-runtime
6、 安裝新的babel-plugin
npm install --save-dev @babel/plugin-proposal-object-rest-spread
npm install --save-dev @babel/plugin-transform-runtime
npm install --save @babel/runtime
7、 修改.babelrc文件

{
    "presets": ["@babel/preset-env", "@babel/preset-react", "mobx"],
    "plugins": [
        "@babel/plugin-proposal-object-rest-spread",
        "@babel/plugin-transform-runtime"
    ]
}
  • 如果你按上述命令安裝完后,相應(yīng)的版本應(yīng)該如下圖所示,問題也應(yīng)該解決了。
"devDependencies": {
    "@babel/core": "^7.2.2",
    "@babel/plugin-proposal-object-rest-spread": "^7.2.0",
    "@babel/plugin-transform-runtime": "^7.2.0",
    "@babel/preset-env": "^7.2.3",
    "@babel/preset-react": "^7.0.0",
    "babel-loader": "^8.0.4",
    "babel-preset-mobx": "^2.0.0",
    "css-loader": "^2.1.0",
    "file-loader": "^3.0.1",
    "popper.js": "^1.14.6",
    "style-loader": "^0.23.1",
    "url-loader": "^1.1.2",
    "webpack": "^4.28.2",
    "webpack-cli": "^3.1.2"
  },
  "dependencies": {
    "@babel/runtime": "^7.2.0",
    "bootstrap": "^4.2.1",
    "jquery": "^3.3.1"
  }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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

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