When using tsup to bundle typescript and generate sourcemaps, it will not generate accurate map files if the target map file already exists in the output directory. It will instead copy the sourcesContent from the existing map file, even if it is completely outdated and incorrect. The built javascript file is updated and correct, only the map file is wrong.
To avoid this currently, clean option must be set to delete the map file, then generate a fresh map.
Steps to reproduce:
Run tsup index.ts --sourcemap
Make some changes to index.ts
Run tsup index.ts --sourcemap again
Note that index.ts.map does not have the correct sourcesContent
There are other ways to show the issue, i.e. using --watch and not having map files updated, or even manually editing the index.js.map file to have incorrectsourcesContent, and running build again to see that it is not changed.
Problem
When using
tsup
to bundle typescript and generate sourcemaps, it will not generate accurate map files if the target map file already exists in the output directory. It will instead copy thesourcesContent
from the existing map file, even if it is completely outdated and incorrect. The built javascript file is updated and correct, only the map file is wrong.To avoid this currently,
clean
option must be set to delete the map file, then generate a fresh map.Steps to reproduce:
tsup index.ts --sourcemap
index.ts
tsup index.ts --sourcemap
againindex.ts.map
does not have the correctsourcesContent
There are other ways to show the issue, i.e. using
--watch
and not having map files updated, or even manually editing theindex.js.map
file to have incorrectsourcesContent
, and running build again to see that it is not changed.Example repo:
https://github.com/garikkh/tsup-sourcemaps-demo/tree/main
Upvote & Fund