Skip to content

fix: ensure JSX transform works after eject with React 17 (#9953) #17109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Aarshpatel12
Copy link

Description

This PR fixes issue #9953 by ensuring that the new JSX transform introduced in React 17 continues to work even after ejecting a Create React App project.

Currently, after ejecting, the Babel configuration does not include the necessary plugin for the new JSX runtime, resulting in ReferenceError: React is not defined unless import React is manually added to every file.

Fix

  • Added @babel/preset-react with runtime: 'automatic' option to the Babel configuration in the ejected Webpack setup.
  • Ensured consistent JSX transformation behavior both before and after ejecting.
  • This aligns with React 17+ best practices where explicit import React is no longer required when using the automatic runtime.

Related Issue

Closes #9953

Checklist

  • Ensured React 17+ JSX transform works after eject
  • Verified no breaking changes for projects using older JSX runtime
  • Added Babel preset configuration with automatic runtime

Preview

After this fix:

  • Users can remove import React from 'react' safely in component files
  • No more ReferenceError: React is not defined after ejecting

Let me know if further changes are needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v4] Bug: React 17, React is not defined after ejecting
2 participants