Expected Behavior
When the TypeScript source files live in a different directory tree than the outDir, the final bundled sourcemap should contain correct relative sources paths that resolve back to the actual .ts files.
For the reproduction project with source at my-project-1/src/test.ts and output at dist/project-1/, the sourcemap should contain:
"sources": ["../../my-project-1/src/test.ts"]
Resolving from the map file's directory: resolve("dist/project-1", "../../my-project-1/src/test.ts") → my-project-1/src/test.ts ✅
Actual Behavior
The sourcemap contains an incorrect path with one extra ../ level:
"sources": ["../../../my-project-1/src/test.ts"]
Resolving from the map file's directory: resolve("dist/project-1", "../../../my-project-1/src/test.ts") → goes above the project root ❌
This breaks source mapping in browsers, debuggers, and any other sourcemap consumer.
Additional Information
Root cause
TypeScript emits sourcemaps with sources paths relative to the output map file location (inside outDir). For example, when compiling my-project-1/src/test.ts with outDir: "../dist/project-1", TypeScript would write dist/project-1/src/test.js.map containing:
{ "sources": ["../../../my-project-1/src/test.ts"], "sourceRoot": "." }
This is correct when resolved from the map file's directory (dist/project-1/src/):
path.resolve("dist/project-1/src", ".", "../../../my-project-1/src/test.ts")
→ "my-project-1/src/test.ts" ✅
However, @rollup/plugin-typescript returns this sourcemap verbatim from the load hook. Rollup's getCollapsedSourcemap then resolves these source paths relative to path.dirname(id) — the original source file's directory (my-project-1/src/), not the output map file's directory:
path.resolve("my-project-1/src", ".", "../../../my-project-1/src/test.ts")
→ "../my-project-1/src/test.ts" (one level above project root) ❌
The mismatch occurs in findTypescriptOutput (packages/typescript/src/outputFile.ts), which returns the TypeScript-emitted sourcemap without rebasing the sources paths from the output directory to the source file directory.
Steps to reproduce
git clone https://github.com/skrtheboss/rollup-repro-5sqw8ygm
cd rollup-repro-5sqw8ygm
npm install
npm run build
cat dist/project-1/index.js.map | jq .sources
# Actual: ["../../../my-project-1/src/test.ts"] ❌
# Expected: ["../../my-project-1/src/test.ts"] ✅
@rollup/plugin-typescriptExpected Behavior
When the TypeScript source files live in a different directory tree than the
outDir, the final bundled sourcemap should contain correct relativesourcespaths that resolve back to the actual.tsfiles.For the reproduction project with source at
my-project-1/src/test.tsand output atdist/project-1/, the sourcemap should contain:Resolving from the map file's directory:
resolve("dist/project-1", "../../my-project-1/src/test.ts")→my-project-1/src/test.ts✅Actual Behavior
The sourcemap contains an incorrect path with one extra
../level:Resolving from the map file's directory:
resolve("dist/project-1", "../../../my-project-1/src/test.ts")→ goes above the project root ❌This breaks source mapping in browsers, debuggers, and any other sourcemap consumer.
Additional Information
Root cause
TypeScript emits sourcemaps with
sourcespaths relative to the output map file location (insideoutDir). For example, when compilingmy-project-1/src/test.tswithoutDir: "../dist/project-1", TypeScript would writedist/project-1/src/test.js.mapcontaining:{ "sources": ["../../../my-project-1/src/test.ts"], "sourceRoot": "." }This is correct when resolved from the map file's directory (
dist/project-1/src/):However,
@rollup/plugin-typescriptreturns this sourcemap verbatim from theloadhook. Rollup'sgetCollapsedSourcemapthen resolves these source paths relative topath.dirname(id)— the original source file's directory (my-project-1/src/), not the output map file's directory:The mismatch occurs in
findTypescriptOutput(packages/typescript/src/outputFile.ts), which returns the TypeScript-emitted sourcemap without rebasing thesourcespaths from the output directory to the source file directory.Steps to reproduce