From 63796a9160f2da0cda438c52c6206c158adfc12a Mon Sep 17 00:00:00 2001 From: On Saint Tiong Date: Wed, 4 Mar 2026 11:07:31 -0800 Subject: [PATCH] Prevent Crashes by Guarding babel.env Access in RN Babel Preset (#55918) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55918 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 fbshipit-source-id: 65e69c0510bc66930ee3b5f28e20df32d732f990 --- packages/react-native-babel-preset/src/configs/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native-babel-preset/src/configs/main.js b/packages/react-native-babel-preset/src/configs/main.js index ad3dfe46280..efeab765934 100644 --- a/packages/react-native-babel-preset/src/configs/main.js +++ b/packages/react-native-babel-preset/src/configs/main.js @@ -51,7 +51,7 @@ const getPreset = (src, options, babel) => { const transformProfile = options?.unstable_transformProfile ?? babel?.caller(getTransformProfile); - const dev = options?.dev ?? babel.env('development'); + const dev = options?.dev ?? babel?.env('development') ?? false; // Hermes V1 (aka Static Hermes) uses more optimised profiles. // There is currently no difference between stable and canary, but canary