Since React 17, importing React should no longer be necessary.
However, starting a new project with meteor create --react
results in the well-known error
Uncaught ReferenceError: React is not defined
after removing the import
statements.
I finally fixed it in two steps:
meteor npm install @babel/plugin-transform-react-jsx
And setting up .babelrc
{
"plugins": [
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "automatic"
}
]
]
}
I found a pull request (feat: Auto import React on jsx,tsx files by henriquealbert · Pull Request #12327 · meteor/meteor · GitHub) which fixes this problem. So, this looks like a regression.
Also, I’ve set compilerOptions.jsx
to "react-jsx"
in jsconfig.json
, to remove the ts(2686) warnings in VSCode.
I’d like to update the skeleton for meteor create --react
to be consistent with the React documentation, but I think this regression should be fixed first. Otherwise, I’d put my changes into the skeleton to make it work.
What do you think?