[metro-resolver] Import resolution `package.json` lookup for ESM is not Node module resolution compliant
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 5.6k
- Forks
- 696
- Avg merge
- 8m
- Merged PRs (30d)
- 7
Description
As per the algorithm: https://nodejs.org/api/esm.html#resolution-algorithm-specification
We'd expect foo-pkg/bar to be resolving package.json:exports from foo-pkg/package.json first to check for exports. However, currently, it seems that Metro prioritises foo-pkg/bar/package.json
A lot of logic relies on getPackageForModule and getPackage which look up the package.json at the given absolute path, rather than taking the package path into account (as per the spec, see: packageSubpath being separated out)
Reproduction in the form of a unit test: https://github.com/kitten/metro/tree/%40kitten/fix/metro-exports-package-json-priority
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Node ESM resolution algorithm and the reproduction unit test linked in the issue. Trace getPackageForModule and getPackage to see how they choose package.json for foo-pkg/bar. Done means exports resolution checks foo-pkg/package.json before foo-pkg/bar/package.json and the reproduction test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100