@babel/preset-env version 7 not transforming the null-coalescing operator

Viewed 2753

I'm setting up a new node project with typescript and babel.

I'm using @babel/preset-env and @babel/preset-typescript and this is my babel.config.js file:

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

In my code I use the null-coalescing operator (x = a ?? b).

Unfortunately I get an error Jest encountered an unexpected token because the null-coalescing syntax is not recognized.

Shouldn't that be included by default by @babel/preset-env version 7? I'm targeting node 10.

Using babel/plugin-proposal-nullish-coalescing-operator fixes the error but I thought that should not be necessary.

1 Answers

As I know so far that babel preset-env won't support stage-x plugin. This babel/plugin-proposal-nullish-coalescing-operator seems to be at stage-4 for now which means you have to keep using this as plugin.

Related