webpack編譯裝飾器報錯問題

Error: The ‘decorators’ plugin requires a ‘decoratorsBeforeExport’ option, whose value must be a boolean. If you are migrating from Babylon/Babel 6 or want to use the old decorators proposal, you should use the ‘decorators-legacy’ plugin instead of ‘decorators’.
解決辦法:

cnpm install babel-plugin-transform-decorators-legacy  --save-dev
cnpm install  @babel/plugin-proposal-decorators --save-dev

cnpm install  @babel/plugin-proposal-class-properties --save-dev

修改babel部分,添加代碼

 "plugins": [
      ["@babel/plugin-proposal-decorators", { "legacy": true }],
      ["@babel/plugin-proposal-class-properties", { "loose" : true }]
    ]


就ok了
如果用的是vscode有提示報錯 “experimentalDecorators”
解決辦法:
點擊Visual Studio Code左下角的配置按鈕(或者文件>首選項>配置),打開用戶設置窗口,在搜索框內輸入“experimentalDecorators”

"javascript.implicitProjectConfig.experimentalDecorators": false  
// 把false改成true 重啓編輯器就可以了
--------------------- 
作者:一直快樂的前端狗 
來源:CSDN 
原文:https://blog.csdn.net/ZhangYaBo_Code/article/details/83066844 
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章