Bable配置decorator报错

Pines_Cheng
  • 6.3k

配置:
"babel-core": "^6.17.0",

{
  "plugins": [
    "transform-class-properties",
    "transform-es2015-block-scoping",
    ["transform-es2015-classes", {"loose": true}],
    "transform-proto-to-assign",
    "transform-decorators-legacy",
    "transform-es2015-modules-commonjs"
  ],
  "presets": [
    "react",
    "es2015",
    "stage-0"
  ]
}

报错:

Method has decorators, put the decorator plugin before the classes one.

回复
阅读 3.7k
2 个回答

参考:babel-plugin-transform-decorators-legacy

NOTE: Order of Plugins Matters!

If you are including your plugins manually and using transform-class-properties, make sure that transform-decorators-legacy comes before transform-class-properties.

/// WRONG

"plugins": [
  "transform-class-properties",
  "transform-decorators-legacy"
]

// RIGHT

"plugins": [
  "transform-decorators-legacy",
  "transform-class-properties"
]

挖出一篇老问题,legacy 的位置很重要

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

宣传栏