Resolver: Remaining differences from Node in `"exports"` resolution
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript
Hướng nghiên cứu
Start in packages/metro-resolver/src/PackageExportsResolve.js, packages/metro-resolver/src/utils/matchSubpathPattern.js, packages/metro-resolver/src/utils/matchSubpathFromExportsLike.js, and packages/metro-file-map/src/lib/TreeFS.js, then compare the listed cases against Node’s require.resolve. The issue identifies several concrete mismatches, but does not name tests to run. Done means the applicable cases produce Node-compatible resolution results or Metro resolution errors instead of raw exceptions or silent incorrect resolutions.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
With #2160, Metro follows Node's PACKAGE_RESOLVE for which package.json and subpath to use with "exports". A comparison with Node (AI-driven, against require.resolve on Node 26, and on Node 24 for Windows) found these remaining differences. Unless noted, they reproduce with resolver.unstable_resolveExportsFromPackageRoot on or off, so they aren't new with that flag.
I've left out Metro's warn-and-fall-back for unexported subpaths and invalid configs, which is intentional for now, and pkg/ resolving as pkg where there's a "." entry (Node says not exported), which we're keeping because require('x/') is a common idiom.
None of these look common. I'd start with the TypeErrors, since those fail on packages that work in Node.
Metro fails where Node resolves
| Case | Specifier | Node | Metro | Code |
|---|---|---|---|---|
"exports": false (or true, 1), with "main": "m.js" |
pkg |
m.js |
Raw TypeError |
Non-object WeakMap key |
package.json is a symlink to store/manifest.json, with "exports": {".": "./root.js"} and root.js beside the symlink |
pkg |
node_modules/pkg/root.js |
Warns about a missing file, fails to resolve | Targets are relative to the manifest's real directory |
No "exports", "main": "lib/m.js" |
pkg/. |
lib/m.js |
Raw Error: Unexpectedly escaped traversal |
TreeFS invariant |
No root package.json, sub/package.json has "main" |
pkg//sub |
sub/main.js |
Fails to resolve | |
missing doesn't exist, or @m has no package |
missing/../pkg/a.js, @m/../pkg/a.js |
pkg/a.js under require |
Fails to resolve |
pkg/. also throws that raw Error for a package with "exports". Node rejects those too, but we should fail with a resolution error.
Metro resolves where Node rejects
These are silent, with no warning.
| Case | Specifier | Node | Metro | Code |
|---|---|---|---|---|
"exports": {"./lib*": "./dist/lib*.js"} |
pkg/lib |
ERR_PACKAGE_PATH_NOT_EXPORTED |
dist/lib.js |
No length check without a trailer |
"exports": {"./a/": "./ok.js"} |
pkg/a/ |
ERR_PACKAGE_PATH_NOT_EXPORTED |
ok.js |
Exact match on a key ending in / |
"exports": {"./a": "./NODE_MODULES/a.js"} |
pkg/a |
ERR_INVALID_PACKAGE_TARGET |
NODE_MODULES/a.js |
Case-sensitive segment check |
"exports": {"./a": {"0": "./x.js", "default": "./y.js"}} |
pkg/a |
ERR_INVALID_PACKAGE_CONFIG |
y.js |
Numeric condition keys aren't rejected |
"exports": {"./a": "./x.js", "#b": "./y.js"} |
pkg/a |
ERR_INVALID_PACKAGE_CONFIG |
x.js |
# keys count as subpaths |
Other
- Percent-encoding: Node decodes
pkg/%2e%2e/secret.jsand throwsERR_INVALID_MODULE_SPECIFIER, and it rejects a target like./%2e%2e/b.jswithERR_INVALID_PACKAGE_TARGET. Metro treats these as literal paths, so they warn about a missing file and then fall back. They can't escape the package. - Windows: With
"exports": {"./shim": "./dist/shim.js"}and a nestedshim/package.json,require('pkg\\shim')in Node gets the nested package'smain, ignoring"exports". With the flag on, Metro normalises the backslash, so it getsdist/shim.js. I've only confirmed Metro's side of this one from a review run and the code. - POSIX backslashes: With
"exports": {"./f": "./lib\\f.js"}, Node resolveslib/f.json any platform. Metro on macOS and Linux treats the backslash literally, so it warns about a missing file. Windows matches Node. - Windows trailing slashes: With a target like
"./a.js/"or"./img.png/", Node 24 on Windows resolves the file. Metro warns and fails on every platform, matching Node on POSIX. - Pattern matches with the flag off: With
"exports": {"./p/*": "./lib/*"}and the flag off,pkg/p/g/../f.jsandpkg/p/g/node_modules/h.jsresolve where Node throwsERR_INVALID_MODULE_SPECIFIER. Enablingresolver.unstable_resolveExportsFromPackageRootfixes this.
Fixed
- #2089: Fallback arrays in
"exports"and"imports"are tried in order, including[{"never": "./dist/y.never.js"}, "./dist/y.js"],["not-valid", "./dist/x.js"]and[null, "./dist/n.js"]. - #2089: Targets with an empty segment, such as
"./dist//c.js", resolve.
- Ngôn ngữ chính
- JavaScript
- Star
- 5.7k
- Fork
- 715
- Merge trung bình
- 3 ngày 14 giờ
- Pull request đã merge (30 ngày)
- 77
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của react/metro
-
[metro-file-map] An error a watcher backend reports ends the server, since nothing listens for itCó thể đã có người làm @sorinc03 đã nhận 3 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Resolver: Read `exports` from the package root, not the closest `package.json`Có thể đã có người làm @robhogan đã nhận hôm nay. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
react/metro#2153 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
metro-file-map gives up on a fallback watcher that is still starting after a fixed 240 s, and leaves it runningCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Published declarations import types from connect, @babel/core and @babel/traverse, whose @types packages are not dependenciesCó thể đã có người làm @sorinc03 đã nhận 3 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
502 on Node 26: ERR_INVALID_ARG_VALUE: Setting the TLS ServerName to an IP address is not permittedĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
github/paste-markdown#129 · 2 reaction ·
-
bug
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 83/100
obsidianmd/obsidian-help#1164 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
richardcase/skills#26 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày