Open
Description
Issue Description
There appears to be an inconsistency between how Metro bundler and Node.js resolve package.json files for the same package. This can lead to different behavior depending on the runtime environment.
Reproduction Steps
- Set up a package with nested package.json files:
node_modules/msw/
├── lib/
│ └── [original files]
├── lib2/
│ └── [copied files]
├── native/
│ └── package.json # Modified to use lib2
└── package.json # using lib
- Modified
node_modules/msw/native/package.json
to uselib2
instead oflib
:
{
"type": "commonjs",
"browser": null,
"main": "../lib2/native/index.js",
"module": "../lib2/native/index.mjs",
"types": "../lib2/native/index.d.ts",
"exports": {
".": {
"react-native": {
"import": {
"types": "./../lib2/native/index.d.mts",
"default": "./../lib2/native/index.mjs"
},
"default": {
"types": "./../lib2/native/index.d.ts",
"default": "./../lib2/native/index.js"
}
}
// ... other exports
}
}
}
- Test in two environments:
- Node.js environment: Uses
n 611E ode_modules/msw/package.json
- Metro bundler environment: Uses
node_modules/msw/native/package.json
- Node.js environment: Uses
Expected Behavior
Both Node.js and Metro bundler should resolve the same package.json file for a given package, ensuring consistent behavior across environments.
Actual Behavior
- Node.js picks up
node_modules/msw/package.json
- Metro bundler picks up
node_modules/msw/native/package.json
Impact
This inconsistency can lead to:
- Different module resolution paths
- Inconsistent behavior between development and production
- Potential runtime errors when switching between Node.js and Metro environments
Test Cases
- Node.js test case: node-msw-test
- Metro test case: my-app/metro-bundler
Environment
- Metro version: v0.82.4
- Node.js version: v22.15.0
- React Native version: v0.79.3
Additional Context
This issue was discovered while working with the MSW (Mock Service Worker) package, but it could affect any package with nested package.json files.
Screenshots
[Include the screenshots showing the different outputs from Node.js and Metro]
Metadata
Metadata
Assignees
Labels
No labels