Babel @babel/plugin-transform-typescript cause an error with regular JavaScript files with JSX?

Viewed 11

In my project I have a mixed JavaScript/TypeScript files. Babel config is:

{
  "presets": [
    ["@babel/preset-env", {
      "corejs": 3,
      "useBuiltIns": "usage",
      "bugfixes": true
    }],
    "@babel/preset-react",
    "@babel/preset-typescript"
  ],
  "plugins": [
    ["@babel/plugin-transform-typescript", {
      "allowDeclareFields": true
    }],
    "@babel/plugin-proposal-class-properties"
  ]
}

The plugin @babel/plugin-transform-typescript is causing the following error on a regular JavaScript file .js, with a JSX definition (where OrderItem is used):

Syntax Error: Unexpected token, expected ",".

createRoot(this.element).render(<OrderItem />);

Aa soon as I remove the plugin, works like charm. Any idea? What's wrong with my configuration?

0 Answers
Related