fix(misc): add react-native export condition for Hermes-safe resolution#2393
Merged
mandarini merged 1 commit intoMay 22, 2026
Merged
Conversation
Metro on Expo SDK 55+ (with `unstable_enablePackageExports` enabled by default) resolves the `import` export condition before `require`, so it picks `dist/index.mjs` — which still contains the dynamic `import()` for `@opentelemetry/api`. Hermes rejects `import()` at parse time, breaking every React Native release build with `Invalid expression encountered`. PR supabase#2381 fixed the CJS bundle (Hermes-safe), but Metro never sees it because the `import` condition wins. Adding a `react-native` condition that points to `dist/index.cjs` makes Metro pick the Hermes-safe bundle without affecting any other consumer: - Vite / webpack / Turbopack / Next.js: unchanged (still resolve `import`). - Node ESM: unchanged (still resolves `import`). - Node CJS / Bun / Deno: unchanged (still resolve `require`). - Metro (React Native): now resolves `react-native` -> `dist/index.cjs`. Verified locally on the original reproducer (`expo export:embed` + `hermesc`): on `@supabase/supabase-js@2.106.1` with only this exports change applied, hermesc exits 0 and the resulting `.hbc` contains no `import()` expressions. Adds a 4th assertion to `test/bundle-hermes-compat.test.cjs`: - `exports["."]` and `exports["./cors"]` both define `"react-native"`. - `"react-native"` appears before `"import"` and `"require"` in key order (Node-style conditional exports resolve in declaration order). - `"react-native"` resolves to a `.cjs` target (Hermes-safe). Refs supabase#2380.
@supabase/auth-js
@supabase/functions-js
@supabase/postgrest-js
@supabase/realtime-js
@supabase/storage-js
@supabase/supabase-js
commit: |
mandarini
approved these changes
May 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
v2.106.1(#2381) fixed the CJS bundle so it no longer containsimport('@opentelemetry/api')— hermesc-safe. However, Metro on Expo SDK 55+ never resolves the CJS bundle: withunstable_enablePackageExportsenabled by default (Metro 0.82+), the"import"condition wins over"require", so Metro picksdist/index.mjs, which still contains the dynamicimport(). Hermes rejects it at parse time:Every React Native release build on
2.106.0/2.106.1fails on Expo SDK 55. Reproducible withexpo export:embed --platform android && hermesc <bundle>— bothexpoandhermescare pre-bundled with Expo SDK 55.This is a different code path from the one #2381 addressed (Metro consuming the CJS bundle). Reports in #2380 from users still on
2.106.1confirm Expo SDK 55 still fails.Refs #2380.
Fix
Add a
"react-native"condition toexports["."]andexports["./cors"], placed before"import"and"require", pointing to the existing Hermes-safedist/*.cjsbundles. Metro recognizes thereact-nativecondition by default (Metro'sresolverMainFieldsandunstable_conditionNames)."exports": { ".": { + "react-native": { + "types": "./dist/index.d.cts", + "default": "./dist/index.cjs" + }, "import": { "types": "./dist/index.d.mts", "default": "./dist/index.mjs" }, "require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" } },Effect by consumer:
import→dist/index.mjsimport→dist/index.mjsrequire→dist/index.cjsimport→dist/index.mjs(broken)react-native→dist/index.cjs✅The fix does not change the build pipeline, doesn't touch
@supabase/tracing, and doesn't introduce new code paths. It's a pure exports-map change: Metro picks the bundle that PR #2381 already made Hermes-safe.Verification
Reproduced and verified locally on the original failing build (
expo export:embed+ bundledhermescfrom React Native 0.83.6, Expo SDK 55.0.26):2.106.1, unchanged):hermescexits 2,Invalid expression encounteredat theimport(OTEL_PKG)call indist/index.mjs(Metro resolved the ESM bundle).2.106.1'spackage.jsononly (no rebuild):dist/index.cjs.import(occurrences.hermescexits 0; output.hbc(11M) is valid.Test artifacts available on request — happy to attach the bundle/log.
Regression test
Extends
test/bundle-hermes-compat.test.cjswith a 4th check onpackage.jsonitself:exports["."]andexports["./cors"]define a"react-native"condition."react-native"appears before"import"and"require"(Node-style conditional exports resolve in declaration order — placement matters when bundlers also match later conditions)."react-native"resolves to a.cjstarget (Hermes-safe by construction).This catches future regressions where someone reorders the conditions or accidentally points
react-nativeat the ESM bundle. Wired into the existingmodule-resolutionCI job throughnpm run test:hermes-compat.Why this approach over alternatives
/tracingentrypoint. Cleanest architecturally but requires an opt-in API change for OTel users — breaking change for2.106.xconsumers who already wired up tracing.loadOtel()toeval('import(...)')or similar. Sidesteps hermesc but trips browser strict CSP (unsafe-eval).react-nativeexport condition. Zero source code changes, zero consumer-facing changes, leverages the Hermes-safe CJS bundle that fix(misc): hide dynamic import from hermesc #2381 already produces. Metrounstable_enablePackageExportswas added specifically to support this kind of platform-specific resolution.