Plugin/Preset files are not allowed to export objects,webpack報錯/babel報錯的解決方法

 

一、爲何會報錯 ?

  這裏抱着錯誤是由於 babel 的版本衝突。javascript

  可能是由於你的 babel 依賴包不兼容。html

 

  能夠查看你的 package.json 的依賴列表java

  即有 babel 7.0 版本的( @babel/core , @babel/preset-react )node

  也可命令查看 bebel-cli 的版本 ( babel -V )react

  也有 babel 6.0 版本的 ( babel-core@6.26.0 , babel-cli@6.26.0 , babel-preset-react@6.24.1 )webpack

  

  若是在你的 package.json 依賴包中既有 babel 7.0 版本,又有 babel 6.0 版本,就會報這個錯誤web

  很現實就是兩個版本是不兼容的npm

 

 

二、處理方法

 

  一、升級到 babel 7.0json

  

  將全部有關 babel 的包都升級爲 7.0 版本babel

"@babel/core": "^7.0.0-beta.40",
"@babel/cli": "^7.0.0-beta.40",
"babel-loader": "^8.0.0-beta.0",
"babel-plugin-lodash": "^3.3.2",
"babel-plugin-react-transform": "^3.0.0",
"@babel/preset-react": "^7.0.0-beta.40",
"@babel/preset-stage-0":'^7.0.0'

  

  而且修改 .babelrc 文件

  對應的修改  presets 預設和 plugins 都改成 7.0 形式。

   query: {
      presets: ['@babel/react', '@babel/stage-0'],
      plugins: ['']
    }

  

 

  二、降級到 babel 6.0 版本

  

  有時候咱們看們的 package.json 裏面都是 babel 6.0 版本的。

  以下:

  

    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-stage-0": "^6.24.1",

  可是仍是報錯,爲何呢?

 

  你不妨把 node_modules 刪掉,從新 install ,這樣就能夠處理一部分兼容問題

 

  若是上面的方法仍是不行。

  你能夠查看一下 babel-cli 的版本

babel -V

  若是是 babel-cli 7.0 版本。

  

  那你就從新安裝全局和本地的 babel-cli 版本爲 6.0

 

npm install -g babel-cli@6.26.0

yarn add babel-cli@6.26.0

  

  

  基本上面兩個方法能夠解決全部兼容問題。

  


  http://www.javashuo.com/article/p-apmixizm-kt.html 

   個人博客 :  XiaoLong's Blog

   博客園小結巴巴: https://www.cnblogs.com/jiebba

相關文章
相關標籤/搜索