Pull Request Overview
- Opened on September 18, 2026
- Status Closed
- Commit count 0
Total Delta
Open Days
Test Delta
How long has this pull request spent in each phase of its lifecycle?
Data pending calculation for pull request
add react-native export condition resolving to browser build
Problem
Follow-up to #397 / #399 and facebook/metro#1681.
Metro resolves package exports with the conditions import/require plus react-native. It never sets browser or node, so for lru-cache it falls through to default, i.e. dist/esm/index.min.js, which does import('node:diagnostics_channel').
Current Metro does recognise the .catch()-guarded dynamic import as optional at build time (the fix from metro#1681), so bundling succeeds. On native, though, the runtime require of an unresolved optional module reports a fatal error through ErrorUtils.reportFatalError instead of throwing, so the promise .catch() never sees it and the app crashes on startup. This is not the node condition being loaded by mistake; it is the default entry.
Change
Add a react-native condition to the root export, in both tshy.exports and the generated exports, pointing at the existing browser build (dist/{esm,commonjs}/browser/). No new build output, no source change. react-native is the conventional condition packages use to give Metro a dedicated entry, and every other resolver ignores it.
Verified with a bare-specifier probe against this branch after npm run prepare:
[node <default>]
require -> dist/commonjs/node/index.min.js
import -> dist/esm/node/index.min.js
[node --conditions=react-native]
require -> dist/commonjs/browser/index.min.js
import -> dist/esm/browser/index.min.js
[node --conditions=browser]
require -> dist/commonjs/browser/index.min.js
import -> dist/esm/browser/index.min.js
tshy preserves the condition on rebuild (git status clean apart from this diff). Browser builds contain no node: references.
Not touched: the ./raw export, which is generated by tshy from source. React Native users importing lru-cache/raw would still hit the default build; happy to hand-write that export too if you'd prefer.
π€ Generated with Claude Code
PR was closed without comments.