【发布时间】:2017-05-25 11:53:33
【问题描述】:
尝试在我的 React 项目中使用装饰器,尽管我已经安装了启用它们的 babel 插件,并在 .babelrc 中引用了该插件,但我的控制台中仍然出现语法错误。
package.json
// ...
"devDependencies": {
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-object-rest-spread": "^6.16.0",
"chai": "^3.5.0",
"file-loader": "^0.9.0",
"url-loader": "^0.5.7"
}
// ...
.babelrc - 我之前安装了transform-object-rest-spread 插件,所以刚刚扩展了plugins 数组:
{
"plugins": ["transform-object-rest-spread", "transform-decorators-legacy"]
}
以及控制台错误,完整(以防万一):
BabelLoaderError: SyntaxError: Decorators are not officially supported yet in 6.x pending a proposal update.
However, if you need to use them you can install the legacy decorators transform with:
npm install babel-plugin-transform-decorators-legacy --save-dev
and add the following line to your .babelrc file:
{
"plugins": ["transform-decorators-legacy"]
}
The repo url is: https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy.
我错过了什么?
【问题讨论】:
-
同时发布你的 webpack 配置
-
糟糕,刚收到您的回复,我就解决了:) 查看答案...
标签: reactjs plugins webpack decorator babeljs