【解决】 @babel/plugin-proposal-decorators 报错
截图如下
场景:
学习装饰器模式,为浏览器兼容,使用babel转换代码
问题复现
1. 安装
npm install --save-dev @babel/plugin-proposal-decorators
2. 配置.babelrc
{
"presets": [
["@babel/preset-env" ]// ES语法转换
],
"plugins": [
["@babel/plugin-proposal-decorators"]
]
}
3. 启动webpack-dev
E:\codes\JavaScript\Design Patterns>npm run dev
design-patterns@1.0.0 dev E:\codes\JavaScript\Design Patterns
webpack-dev-server --config ./webpack.dev.config.js --mode development
4.报错
解决
.babelrc添加配置,更改如下
{
"presets": [
["@babel/preset-env" ]// ES语法转换
],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }]
]
}
参考:
https://segmentfault.com/a/1190000021556489
https://www.babeljs.cn/docs/babel-plugin-proposal-decorators