1. 程式人生 > >babel版本兼容報錯處理:Plugin/Preset files are not allowed to export objects

babel版本兼容報錯處理:Plugin/Preset files are not allowed to export objects

cor cin 就會 babel containe 錯誤 lpad 什麽 dex

原文地址:

https://www.cnblogs.com/jiebba/p/9618930.html

1、為什麽會報錯 ?

  這裏抱著錯誤是因為 babel 的版本沖突。

  多是因為你的 babel 依賴包不兼容。

  可以查看你的 package.json 的依賴列表

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

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

  也有 babel 6.0 版本的 ( [email protected] , [email protected] , [email protected] )

  

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

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

2、處理方法

  1、升級到 babel 7.0

  

  將所有有關 babel 的包都升級為 7.0 版本

1 2 3 4 5 6 "@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",<br>"@babel/preset-stage-0":‘^7.0.0‘

  

  並且修改 .babelrc 文件

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

1 2 3 4 query: { presets: [‘@babel/react‘, ‘@babel/stage-0‘], plugins: [‘‘] }

  

  2、降級到 babel 6.0 版本

  

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

  如下:

  

1 2 3 4 5 "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 的版本

1 babel -V

  如果是 babel-cli 7.0 版本。

  

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

1 2 3 npm install -g [email protected] yarn add [email protected]

  

  

  基本上面兩個方法可以解決所有兼容問題。

babel版本兼容報錯處理:Plugin/Preset files are not allowed to export objects