美文网首页
装饰器connect问题:Error: The 'decorat

装饰器connect问题:Error: The 'decorat

作者: ELLENXX | 来源:发表于2019-07-05 16:35 被阅读0次

问题

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'.

解释

“decorators”插件需要一个“decoratorsBeforeExport”选项,其值必须是布尔值。如果您正在从Babylon/Babel 6 迁移过来,或者想使用旧的decorator,您应该使用“decorator -legacy”插件而不是“decorator”。

最开始我想使用rudex的装饰器connect,然后搜了一下博客
第一步:安装babel-plugin-transform-decorators-legacy插件

cnpm install babel-plugin-transform-decorators-legacy

第二步:进行配置

npm run eject

在package.json找到

"babel": {
    "presets": [
      "react-app"
    ],
}

在里面添加:

"babel": {
    "presets": [
      "react-app"
    ],
    "plugins": [
      "transform-decorators-legacy"
    ]
}

结果报错
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-proposal-decorators --save-dev

配置:

"babel": {
    "presets": [
      "react-app"
    ],

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

  }
}

问题解决
如果用的是vscode有提示报错 “experimentalDecorators”
在项目根目录下添加jsconfig.json文件

{

  "compilerOptions": {

    "experimentalDecorators": true

  }

}

相关文章

网友评论

      本文标题:装饰器connect问题:Error: The 'decorat

      本文链接:https://www.haomeiwen.com/subject/qepehctx.html