【问题标题】:@babel/preset-env version 7 not transforming the null-coalescing operator@babel/preset-env 版本 7 未转换 null-coalescing 运算符
【发布时间】:2020-08-04 16:21:03
【问题描述】:

我正在使用 typescript 和 babel 建立一个新的节点项目。

我正在使用@babel/preset-env@babel/preset-typescript,这是我的babel.config.js 文件:

module.exports = {
  presets: [
    [
      "@babel/preset-env",
      {
        targets: {
          node: "current",
        },
      },
    ],
    "@babel/preset-typescript",
  ],
  plugins: [
  ],
};

在我的代码中,我使用空合并运算符 (x = a ?? b)。

很遗憾,我收到错误 Jest encountered an unexpected token,因为无法识别空合并语法。

@babel/preset-env 版本 7 不应该默认包含它吗?我的目标是节点 10。

使用babel/plugin-proposal-nullish-coalescing-operator 修复了错误,但我认为这不是必需的。

【问题讨论】:

    标签: javascript node.js typescript babeljs


    【解决方案1】:

    据我所知,babel preset-env 不支持 stage-x 插件。这个babel/plugin-proposal-nullish-coalescing-operator 现在似乎在stage-4,这意味着你必须继续使用它作为插件。

    【讨论】:

    猜你喜欢
    • 2018-07-02
    • 2019-03-17
    • 2012-02-12
    • 1970-01-01
    • 2018-04-27
    • 2019-03-20
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    相关资源
    最近更新 更多