【问题标题】:decoratorsBeforeExport Error when using electron-webpack dev使用electron-webpack dev时的decoratorsBeforeExport错误
【发布时间】:2019-06-20 22:19:22
【问题描述】:

我试图将我的 react 项目转换为电子应用程序。作为 该项目是通过 webpack 捆绑的,我开始使用 electron-webpack 构建。运行 electron-webpack dev 时,/main 和 /renderer 都无法正确编译。

控制台日志抛出装饰器插件错误

The decorators plugin requires a 'decoratorsBeforeExport' option,
 whose value must be a boolean. If you want to use the 
legacy decorators semantics, you can set the 'legacy: true' option

Sooo,为什么不遵循这个明智的建议呢?然后,我更新了所有依赖项并更新了我的 .babelrc 文件,以添加 decoratorsBeforeExport 和 legacy 选项(false 和 分别为真)

"plugins": [
   ["@babel/plugin-proposal-decorators", {
     "decoratorsBeforeExport": false,
     "legacy": true,
   }],

由于此后仍然显示错误,我从 _/node_modules_ 打开 plugin-proposal-decorators文件夹并为 options 添加了一个日志。显然,它没有识别我的选项集。我试过了 直接从 webpack 加载器配置,但问题仍然存在。

我的环境

  • 节点:v11.2.0
  • Webpack:v4.29.0
  • @babel/core: v7.0.0

【问题讨论】:

    标签: javascript webpack electron babeljs


    【解决方案1】:

    这个.babelrc 为我工作:

    {
      "presets": [
        "@babel/preset-react",
        [ "@babel/preset-env", {
          "targets": {
            "browsers": [ "last 1 version" ]
          }
        } ]
      ],
      "plugins": [
        "@babel/plugin-proposal-object-rest-spread",
        ["@babel/plugin-proposal-decorators", { "legacy": true }],
        ["@babel/plugin-proposal-class-properties", { "loose" : true }]
      ]
    }
    

    注意decorators 插件是如何出现在class-properties 之前的。

    不知何故,它在非legacy 模式下对我不起作用。如果decorators 在legacy 模式下运行,则需要loose 选项,根据官方文档:https://babeljs.io/docs/en/next/babel-plugin-proposal-decorators.html

    它还指出:

    在 Babel 7 中,transform-decorators-legacy 将是 Stage-0 中的默认插件。 (来源:https://babeljs.io/docs/en/babel-plugin-transform-decorators.html)

    更多信息: Babel 7 - Decorators transform doesn't work with babel-loader Simple ES7 decorator with babel

    【讨论】:

      猜你喜欢
      • 2020-01-01
      • 1970-01-01
      • 2017-06-14
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-11
      • 2018-07-17
      相关资源
      最近更新 更多