Skip to content

Prevent Crashes by Guarding babel.env Access in RN Babel Preset - #55918

Closed
onsaint wants to merge 1 commit into
react:mainfrom
onsaint:export-D94952379
Closed

Prevent Crashes by Guarding babel.env Access in RN Babel Preset#55918
onsaint wants to merge 1 commit into
react:mainfrom
onsaint:export-D94952379

Conversation

@onsaint

@onsaint onsaint commented Mar 4, 2026

Copy link
Copy Markdown

Summary:
To prevent crashes when a Babel plugin or preset is invoked without a Babel API object, ensure that any access to Babel-specific properties (such as babel.env) is guarded. Some build tools or environments may call Babel plugins without providing the full Babel API instance, leading to runtime errors if the code assumes its presence. By using optional chaining and providing safe fallbacks, you can maintain compatibility across different build systems (such as Metro and others) without introducing breaking changes.

Changelog:
[General][Fixed] Prevent errorrs by handling contexts where the Babel API object is not provided

Reviewed By: robhogan, rubennorte

Differential Revision: D94952379

Summary:
To prevent crashes when a Babel plugin or preset is invoked without a Babel API object, ensure that any access to Babel-specific properties (such as babel.env) is guarded. Some build tools or environments may call Babel plugins without providing the full Babel API instance, leading to runtime errors if the code assumes its presence. By using optional chaining and providing safe fallbacks, you can maintain compatibility across different build systems (such as Metro and others) without introducing breaking changes.

Changelog:
[General][Fixed] Prevent errorrs by handling contexts where the Babel API object is not provided

Reviewed By: robhogan, rubennorte

Differential Revision: D94952379
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 4, 2026
@meta-codesync

meta-codesync Bot commented Mar 4, 2026

Copy link
Copy Markdown

@onsaint has exported this pull request. If you are a Meta employee, you can view the originating Diff in D94952379.

@meta-codesync

meta-codesync Bot commented Mar 4, 2026

Copy link
Copy Markdown

This pull request has been merged in 63796a9.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Mar 4, 2026
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by On Saint Tiong in 63796a9

When will my fix make it into a release? | How to file a pick request?

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants