8000 Metro Resolver and Node.js Resolve Different package.json Files for the Same Package · Issue #1517 · facebook/metro · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Metro Resolver and Node.js Resolve Different package.json Files for the Same Package #1517
Open
@algoORgoal

Description

@algoORgoal

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

  1. 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
  1. Modified node_modules/msw/native/package.json to use lib2 instead of lib:
{
  "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
    }
  }
}
  1. 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

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:

  1. Different module resolution paths
  2. Inconsistent behavior between development and production
  3. Potential runtime errors when switching between Node.js and Metro environments

Test Cases

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]

  • output from node.js
    the output of node.js

  • output from metro
    the output of metro

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0