From 2f4607c65c714c828d48d500307415c8cf317854 Mon Sep 17 00:00:00 2001 From: Cuc Dan Mihai Date: Thu, 16 Jul 2026 14:05:38 +0300 Subject: [PATCH] fix(resource-fetcher): avoid 'this' in static fs field initializer An async arrow inside the static 'fs' class-field initializer relies on 'this' binding to the class. When an app resolves the library through the "react-native": "src/index" entry, Metro compiles this TS source with the app's Babel config; under @react-native/babel-preset with unstable_transformProfile 'hermes-stable' or 'hermes-canary', the async transform hoists the arrow's 'this' capture (var _this = this) to module scope. ResourceFetcher.fs.readAsString then calls _this.getAdapter() on the module context and every LLM/model load fails with 'TypeError: undefined is not a function' right after download. Referencing the class by name sidesteps the transform entirely. Co-Authored-By: Claude Fable 5 --- packages/react-native-executorch/src/utils/ResourceFetcher.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/react-native-executorch/src/utils/ResourceFetcher.ts b/packages/react-native-executorch/src/utils/ResourceFetcher.ts index 7b31f65584..56b9923fb3 100644 --- a/packages/react-native-executorch/src/utils/ResourceFetcher.ts +++ b/packages/react-native-executorch/src/utils/ResourceFetcher.ts @@ -138,8 +138,10 @@ export class ResourceFetcher { * @remarks * **REQUIRED**: Used internally for reading configuration files (e.g., tokenizer configs). */ + // Reference the class by name: `this` inside a static-field arrow gets + // rebound to module scope by Babel under RN's hermes transform profiles. readAsString: async (path: string) => { - return this.getAdapter().readAsString(path); + return ResourceFetcher.getAdapter().readAsString(path); }, }; }