react / react/metro

Metro can't resolve transitive dependencies when using bun as package manager

Open
#1,636 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
5.6k
Forks
696
Avg merge
8m
Merged PRs (30d)
7

Description

Summary

When using bun as package manager, Metro bundler cannot resolve transitive dependencies because bun stores them in node_modules/.bun/ rather than hoisting them to node_modules/.

Related

Steps to reproduce

  1. Create an Expo project using bun as package manager
  2. Have code that imports a transitive dependency (e.g., promise which is a dependency of react-native)
  3. Run expo run:ios or expo start

Expected behavior

Metro should be able to resolve promise since it's a dependency of react-native which is installed.

Actual behavior

Unable to resolve module promise/setimmediate/rejection-tracking from /path/to/file.ts:
promise/setimmediate/rejection-tracking could not be found within the project or in these directories:
  node_modules
  ../node_modules

The package exists at node_modules/.bun/promise@8.3.0/node_modules/promise but Metro doesn't look there.

Workaround

Add transitive dependencies as direct dependencies in package.json:

"promise": "^8.3.0"

Environment

  • bun: 1.x
  • expo: 54.0.30
  • react-native: 0.81.5

Possible solutions

  1. Metro could be configured to also look in node_modules/.bun/
  2. Expo/RN could list commonly-needed transitive deps like promise as peerDependencies
  3. Documentation warning about bun compatibility

Notes

This differs from npm/yarn behavior where transitive dependencies are hoisted to root node_modules/ and are resolvable by any package. Bun is increasingly popular so this may affect more users.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with bun using expo run:ios or expo start, importing the transitive promise dependency. Start by tracing Metro's module resolution and compare its search paths with node_modules/.bun/. Done means the transitive dependency resolves under bun without requiring it to be added directly to package.json.

Written by the indexing model from the issue text.

Assessment

Tech stack
bun, javascript
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.