From e62e3d50e3858112e0258ffab92d77e1447b3417 Mon Sep 17 00:00:00 2001 From: Davor Bauk Date: Fri, 18 Sep 2026 15:47:42 -0700 Subject: [PATCH] add react-native export condition resolving to browser build Metro (React Native's bundler) resolves package exports with the conditions `import`/`require` and `react-native`, never `browser` or `node`, so it falls through to the `default` entry. That build does `import('node:diagnostics_channel')`, which cannot be provided in a React Native runtime. Current Metro treats the `.catch()`- guarded import as optional at build time, but on native the runtime `require` of an unresolved optional module reports a fatal error via `ErrorUtils` instead of throwing, so the `.catch()` never runs and the app crashes on startup. Expose the existing browser build under the `react-native` condition as well. This is the conventional way for packages to provide a Metro-specific entry, is ignored by every other resolver, and adds no new build output. Co-Authored-By: Claude Fable 5.1 --- CHANGELOG.md | 3 +++ package.json | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bffe10d..79fafc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ - Add `backgroundFetchSize` option, defaulting to 1, to set an effective size for provisional background fetch objects while in flight, if they do not shadow an existing stale entry. +- Add a `react-native` export condition that resolves to the + browser build, so that Metro does not load the default build, + which imports `node:diagnostics_channel`. ## 11.4 diff --git a/package.json b/package.json index 01dad2a..9527b44 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,10 @@ "./raw": "./src/index.ts", ".": { "import": { + "react-native": { + "types": "./dist/esm/browser/index.d.ts", + "default": "./dist/esm/browser/index.min.js" + }, "browser": { "types": "./dist/esm/browser/index.d.ts", "default": "./dist/esm/browser/index.min.js" @@ -57,6 +61,10 @@ "default": "./dist/esm/index.min.js" }, "require": { + "react-native": { + "types": "./dist/commonjs/browser/index.d.ts", + "default": "./dist/commonjs/browser/index.min.js" + }, "browser": { "types": "./dist/commonjs/browser/index.d.ts", "default": "./dist/commonjs/browser/index.min.js" @@ -124,6 +132,10 @@ }, ".": { "import": { + "react-native": { + "types": "./dist/esm/browser/index.d.ts", + "default": "./dist/esm/browser/index.min.js" + }, "browser": { "types": "./dist/esm/browser/index.d.ts", "default": "./dist/esm/browser/index.min.js" @@ -136,6 +148,10 @@ "default": "./dist/esm/index.min.js" }, "require": { + "react-native": { + "types": "./dist/commonjs/browser/index.d.ts", + "default": "./dist/commonjs/browser/index.min.js" + }, "browser": { "types": "./dist/commonjs/browser/index.d.ts", "default": "./dist/commonjs/browser/index.min.js"