Skip to content

Commit 63796a9

Browse files
On Saint Tiongmeta-codesync[bot]
authored andcommitted
Prevent Crashes by Guarding babel.env Access in RN Babel Preset (#55918)
Summary: Pull Request resolved: #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
1 parent 6b32971 commit 63796a9

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • packages/react-native-babel-preset/src/configs

packages/react-native-babel-preset/src/configs/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const getPreset = (src, options, babel) => {
5151
const transformProfile =
5252
options?.unstable_transformProfile ?? babel?.caller(getTransformProfile);
5353

54-
const dev = options?.dev ?? babel.env('development');
54+
const dev = options?.dev ?? babel?.env('development') ?? false;
5555

5656
// Hermes V1 (aka Static Hermes) uses more optimised profiles.
5757
// There is currently no difference between stable and canary, but canary

0 commit comments

Comments
 (0)