国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

詳解babel升級到7.X采坑總結

2019-11-19 11:35:56
字體:
來源:轉載
供稿:網友

最近工作比較忙,有一段時間沒有寫前端玩了。今天試著搭一個項目,發現各種坑,以前用起來非常好的配置文件各種報錯。排查后發現原來babel升級了一個大版本,已經到7.X了,這里我總結一下升級過程中踩到的坑。

Error: Cannot find module '@babel/core'babel-loader@8 requires Babel 7.x (the package '@babel/core'). If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'.  at Function.Module._resolveFilename (module.js:547:15)  at Function.Module._load (module.js:474:25)  at Module.require (module.js:596:17)  at require (internal/module.js:11:18)  ....

沒找到@babel/core,需要把babel-core卸載掉,從新安裝@babel/core

npm un babel-corenpm i -D @babel/core
ERROR in ./src/index.jsxModule build failed (from ./node_modules/babel-loader/lib/index.js):Error: Plugin/Preset files are not allowed to export objects, only functions....

將babel-preset-*卸載,重新安裝@babel/preset-*,并且修改 .babelrc中的 presets

比如我的

npm:- babel-preset-env+ @babel/preset-env- babel-preset-react+ @babel/preset-react- babel-preset-stage-0.babelrc:- "presets": ["react", "env", "stage-0", "mobx"]+ "presets": ["@babel/preset-react", "@babel/preset-env", "mobx"]

除了上述的preset,我還用了babel-preset-mobx

但是沒找到 @babel/preset-mobx,從babel-preset-mobx git提交日志上看,作者已經支持了最新的babel。在之后的測試中,發現mobx的功能也能正常使用。

另外,stage-*已棄用

ERROR in ./src/index.jsxModule build failed (from ./node_modules/babel-loader/lib/index.js):TypeError: this.setDynamic is not a function  at PluginPass.pre  ...

這次是插件了,一樣把babel-plugin-*卸載,重新安裝@babel/plugin-*

然后修改.babelrc文件

具體的包名可以在 npm倉庫 里找

最終文件

.babelrc:

{  "presets": ["@babel/preset-env", "@babel/preset-react", "mobx"],  "plugins": [    "@babel/plugin-proposal-object-rest-spread",    "@babel/plugin-transform-runtime"  ]}

package.json:

"devDependencies": {  "@babel/core": "^7.1.0",  "@babel/plugin-proposal-object-rest-spread": "^7.0.0",  "@babel/plugin-transform-runtime": "^7.1.0",  "@babel/preset-env": "^7.1.0",  "@babel/preset-react": "^7.0.0",  "babel-loader": "^8.0.2"  "babel-preset-mobx": "^2.0.0",  ... }, "dependencies": {  "@babel/runtime": "^7.0.0",  ... }

總結

這次升級,功能上有什么變化我就不在這里寫了,大家可以自行搜索

總的來說,babel舍棄了以前的 babel-*-* 的命名方式,改成了@babel/*-*

修改依賴和.babelrc文件后就能正常啟動項目了。

webpack不用修改(除非你是webpack 3.X 升webpack 4.X)

上面的只是我遇到的問題,如果還有其他問題,可以參考資料升級指南 Upgrade to Babel 7

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 博爱县| 土默特左旗| 喀喇| 长乐市| 定兴县| 象山县| 呈贡县| 巫溪县| 犍为县| 汝州市| 龙岩市| 海盐县| 龙南县| 兴和县| 德阳市| 宁海县| 长泰县| 壤塘县| 镇巴县| 来宾市| 宣威市| 娱乐| 绥滨县| 淮安市| 瑞安市| 莆田市| 曲靖市| 屯昌县| 盐池县| 瓮安县| 广昌县| 交城县| 凤台县| 汨罗市| 天全县| 册亨县| 康定县| 准格尔旗| 三都| 交口县| 桂阳县|