Incorrect sourcemap sources paths when outDir differs from source directory
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- typescript
- Ambito
- build-system
Direzione di ricerca
Start in packages/typescript/src/outputFile.ts, specifically findTypescriptOutput, and reproduce the issue with the linked project using npm install, npm run build, and jq on dist/project-1/index.js.map. Trace how the emitted sourcemap sources are returned and ensure the final sources resolve to my-project-1/src/test.ts as ../../my-project-1/src/test.ts.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
- Rollup Plugin Name:
@rollup/plugin-typescript - Rollup Plugin Version: 12.3.0
- Rollup Version: 4.59.0
- Operating System (or Browser): Linux (reproducible on any OS)
- Node Version: v24.13.0
- Link to reproduction: https://stackblitz.com/~/github.com/skrtheboss/rollup-repro-5sqw8ygm
- May be ralated to: #1948
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"] ✅
- Lingua principale
- JavaScript
- Stelle
- 3.8k
- Fork
- 636
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rollup/plugins
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
Support js-yaml v5Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
Tutte le issue di rollup/plugins
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
daisy/a11y-meta-viewer#18 ·
-
good first issue status: needs triaging type: bug version: 2.0
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
medusajs/medusa#17094 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
browser: chrome package: @carbon/react package: styles
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
carbon-design-system/carbon#23567 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
clerk/javascript#10033 ·
I maintainer di solito rispondono entro 1 giorno
-
bug client p1
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
vercel/eve#4173 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno