Repository navigation
Description
Have you used AI?
Yes
Bug Description
With TsconfigPathsPlugin (tsconfig option), paths that come from an extended config (with no baseUrl) are resolved relative to the root tsconfig instead of the config that declares them, and ${configDir} in baseUrl is not expanded. tsc resolves all three cases below.
Link to Minimal Reproduction and step to reproduce
Run in an empty directory:
npm i enhanced-resolve@5.26.1
w(){ mkdir -p "$(dirname "$1")"; printf '%s\n' "$2" > "$1"; }
# 1: paths (no baseUrl) declared in an extended config; tsc resolves them relative to that config
w one/src/foo.ts 'export const v = 1;'
w one/tsconfig.json '{ "extends": "./configs/base.json" }'
w one/configs/base.json '{ "compilerOptions": { "paths": { "@/*": ["../src/*"] } } }'
# 2: same, base config from a package
w two/src/foo.ts 'export const v = 1;'
w two/tsconfig.json '{ "extends": "cfgpkg/base.json" }'
w two/node_modules/cfgpkg/package.json '{ "name": "cfgpkg" }'
w two/node_modules/cfgpkg/base.json '{ "compilerOptions": { "paths": { "@/*": ["../../src/*"] } } }'
# 3: baseUrl "${configDir}/src" in an extended config (TS 5.5 template variable)
w three/src/foo.ts 'export const v = 1;'
w three/tsconfig.json '{ "extends": "./configs/base.json" }'
w three/configs/base.json '{ "compilerOptions": { "baseUrl": "${configDir}/src" } }'
node -e '
const fs = require("fs"), path = require("path"), { ResolverFactory, CachedInputFileSystem } = require("enhanced-resolve");
for (const [c, spec] of [["one", "@/foo"], ["two", "@/foo"], ["three", "foo"]]) {
const dir = path.resolve(c);
const r = ResolverFactory.createResolver({ fileSystem: new CachedInputFileSystem(fs, 0), useSyncFileSystemCalls: true,
extensions: [".ts"], tsconfig: path.join(dir, "tsconfig.json") });
try { console.log(c, spec, "->", path.relative(dir, r.resolveSync({}, dir, spec))); } catch (e) { console.log(c, spec, "->", e.message.split("\n")[0]); }
}'Expected Behavior
one @/foo -> src/foo.ts
two @/foo -> src/foo.ts
three foo -> src/foo.ts
This is what ts.resolveModuleName gives with each tsconfig.json. tsc resolves paths without baseUrl relative to the file that declares them: https://www.typescriptlang.org/tsconfig/#paths
Actual Behavior
one @/foo -> Can't resolve '@/foo' in '<dir>/one'
two @/foo -> Can't resolve '@/foo' in '<dir>/two'
three foo -> Can't resolve 'foo' in '<dir>/three'
Environment
enhanced-resolve 5.26.1 (also main at 4e6f2fc)
typescript 5.9.3 (for the tsc comparison)
Node.js v26.13.0, Linux x64Is this a regression?
No
Last Working Version
Additional Context
_loadTsconfigFromExtends in lib/TsconfigPathsPlugin.js rebases an inherited baseUrl to the extended config's directory but keeps inherited paths unanchored, and never substitutes ${configDir} in baseUrl.
Found with a differential-testing tool; the report was drafted with AI assistance and reviewed and edited by me.
Credit: https://ucsbplse.github.io/
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity