[SOLVED] - Why I still need to import react on each jsx/tsx file?

Since React 17 it’s not necessary to import React to use JSX, but even if I’m using React 18 I still need to import react, any thoughts?

Please follow the Manual Babel setup here: https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html

Hi @paulishca, I did try that approach but wasn’t work because meteor will ignore any custom config on @babel/preset-react as mentioned here meteor/babel-compiler.js at devel · meteor/meteor · GitHub

But I’ll give it another shot by using @babel/plugin-transform-react-jsx instead of @babel/preset-react since plugin-transform-react-jsx is not ignore it by meteor.

SOLVED by installing @babel/core @babel/plugin-transform-react-jsx and add custom .babelrc file with following lines

{
  "plugins": [
    [
      "@babel/plugin-transform-react-jsx",
      {
        "runtime": "automatic"
      }
    ]
  ]
}

but I’m not sure if adding a custom babel config will not mess up anything else, please any idea?

1 Like