npx create-react-app my-app
then eject it, it report React is not defined
I have submitted PR #9885 to fix this.
This is because the jsx-runtime configuration gets removed webpack config during the ejection process.
In the meantime, Adding a runtime option to babel in package.json
will solve the issue
// package.json
{
"babel": {
"presets": [
[
"react-app",
{
"runtime": "automatic"
}
]
]
}
}
or add presents option back to webpack.config.js
(around line 409)
// webpack.config.js
{
loader: require.resolve('babel-loader'),
options: {
customize: require.resolve(
'babel-preset-react-app/webpack-overrides'
),
// Add this back
presets: [
[
require.resolve('babel-preset-react-app'),
{
runtime: hasJsxRuntime ? 'automatic' : 'classic',
},
],
],
}
}
Thank you @n3tr! Changing the webpack config as you suggested worked for me.
Thanks, only package.json
solution worked for me.
Edit: This didn't fully work as intended.
After trying a few different things, what worked for me was:
I then just copied my source files over.
Most helpful comment
I have submitted PR #9885 to fix this.
This is because the jsx-runtime configuration gets removed webpack config during the ejection process.
In the meantime, Adding a runtime option to babel in
package.json
will solve the issueor add presents option back to
webpack.config.js
(around line 409)