You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
packageImportsResolve: wildcard imports keys with a trailer (#*.js) never match #56
packageImportsResolve misses wildcard keys with a trailer (#*.js, #lib/*.js) because the pattern base is computed with key.slice(0, -1) instead of key.slice(0, patternIndex).
For key #*.js this tests name.startsWith("#*."), which never matches, so the key is skipped and resolution throws ERR_PACKAGE_IMPORT_NOT_DEFINED. Keys that end in * (#internal/*) work by accident since slice(0, -1) and slice(0, patternIndex) coincide there.
The exports counterpart a few hundred lines up is already correct — the asymmetry is the whole bug:
import{resolveModulePath}from"exsolve";// from node_modules/pkg/index.mjsresolveModulePath("#internal/marker.js",{from: parent,conditions: ["node","import"]});// exsolve 1.1.0: Cannot resolve module "#internal/marker.js"// node: resolves to node_modules/pkg/runtime/internal/marker.js
Node resolves this fine (createRequire(parent).resolve("#internal/marker.js") returns the expected path), so exsolve diverges from the reference implementation here.
I applied this one-character change to the installed exsolve@1.1.0 dist locally and verified all three cases now resolve identically to Node:
specifier
imports map
before
after
#internal/marker.js
"#*.js": "./runtime/*.js"
throws
runtime/internal/marker.js
#ok/x.js
"#ok/*.js": "./local/*.js"
throws
local/x.js
#lib/y.js
"#lib/*.js": "dep/*.js" (external target)
throws
node_modules/dep/y.js
Trailing-star keys and the exports path were unaffected.
Worth a regression test with a trailer-pattern imports key alongside the existing exports fixtures.
Context
Found while reviewing unjs/nf3#66 — @vercel/nft has the same class of bug in its own resolver, and exsolve was the natural patch-free fallback for nf3 until it turned out to share the defect.
Activity
fix: match wildcard `imports` keys with a trailer
fix(trace): resolve wildcard package imports without patching nft