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
- Create an Expo project using bun as package manager
- Have code that imports a transitive dependency (e.g.,
promise which is a dependency of react-native)
- 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:
Environment
- bun: 1.x
- expo: 54.0.30
- react-native: 0.81.5
Possible solutions
- Metro could be configured to also look in
node_modules/.bun/
- Expo/RN could list commonly-needed transitive deps like
promise as peerDependencies
- 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.
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 tonode_modules/.Related
Steps to reproduce
promisewhich is a dependency ofreact-native)expo run:iosorexpo startExpected behavior
Metro should be able to resolve
promisesince it's a dependency ofreact-nativewhich is installed.Actual behavior
The package exists at
node_modules/.bun/promise@8.3.0/node_modules/promisebut Metro doesn't look there.Workaround
Add transitive dependencies as direct dependencies in package.json:
Environment
Possible solutions
node_modules/.bun/promiseas peerDependenciesNotes
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.