We were unable to construct the commit group for this pull request: None of the pull request's commits have been successfully processed as yet.

add react-native export condition resolving to browser build #412

Closed
davor-bauk-sh opened 7:48pm on September 18, 2026 wanted to merge 0 commits into isaacs/node-lru-cache main from
react-native-export-condition

Pull Request Overview

  • Opened on September 18, 2026
  • Status Closed
  • Commit count 0

Total Delta

0 Total Diff Delta

Open Days

Open 1 weekdays

Test Delta

Diff Delta in Test Files
Breakdown by Phase

How long has this pull request spent in each phase of its lifecycle?

Data pending calculation for pull request

Author avatar

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.