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

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 15:39:37
字體:
來源:轉載
供稿:網友

最近工作比較忙,有一段時間沒有寫前端玩了。今天試著搭一個項目,發現各種坑,以前用起來非常好的配置文件各種報錯。排查后發現原來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文件后就能正常啟動項目了。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 常州市| 北票市| 天镇县| 西乌珠穆沁旗| 缙云县| 邵阳县| 霸州市| 三原县| 曲阜市| 宣城市| 光泽县| 钦州市| 淮阳县| 浮梁县| 土默特左旗| 义马市| 杭锦后旗| 建昌县| 华宁县| 庐江县| 从江县| 吉安市| 忻城县| 龙南县| 灌阳县| 富宁县| 西青区| 南阳市| 兴山县| 上饶县| 枣阳市| 莱西市| 海林市| 晋城| 兴海县| 枣强县| 岢岚县| 孟津县| 定日县| 延边| 鄂托克前旗|