Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source URLs in generated source map are wrong when composite is enabled in tsconfig.json #1715

Open
pqnet opened this issue May 4, 2024 · 0 comments

Comments

@pqnet
Copy link

pqnet commented May 4, 2024

  • Rollup Plugin Name: @rollup/plugin-typescript
  • Rollup Plugin Version: 11.1.6
  • Rollup Version: 3.7.5
  • Operating System (or Browser): stackblitz
  • Node Version: 20.12.8
  • Link to reproduction (⚠️ read below): https://stackblitz.com/edit/rollup-repro-wqsugy

Expected Behavior

Section sources in the generated source map (dist/index.js.map) should contain a valid path relative to the source file used to generate the bundle, relative to the position of the source map file itself, in this case ../src/index.ts

Actual Behavior

The path in sources map contains an extra ../ segment, i.e. ../../src/index.ts

Additional Information

Setting composite to true instructs the typescript compiler to copy the directory structure of the source files relative to the root dir (by default it's the tsconfig.json file location), hence it expects the source map file to be generated in dist/src/index.js.map, which does not match the path in the imported module ID.

The root cause is that the source map produced by Typescript has its path relative to the output file generated by Typescript, while the one expected by rollup should be relative to the module id (the input file in this case).
This happens to match if the input (.ts) file and the output (.js) files are in the same directory or in directories with the same path depth.

See
https://github.com/rollup/plugins/blob/master/packages/typescript/src/outputFile.ts#L89

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant