This repository is intended to demo an existing issue in tsup related to sourcemap generation.
If the target sourcemap (dist/index.js.map) exists, tsup will not generate
correct sourcemaps when building/bundling code. It will instead use the sourcesContent
from the existing file.
To workaround this issue, you need to use clean option in tsup.
- Run
npm run buildto build an initialdist/index.jsanddist/index.js.map - Make some changes in
index.ts - Run
npm run buildagain. - Note that
dist/index.jshas the updated changes, butdist/index.js.mapdoes NOT have the correctsourcesContent.
The same can be observed with running npm run watch.
Following the same steps as above, if the scripts build:clean or watch:clean are used,
the dist folder contents are deleted and tsup generates fresh .js.map files correctly.
- This issue does not exist in
swc, can be tested using the same steps as above andbuild:swcscript instead ofbuild. - Also tested with
esbuildusingbuild:esbuildscript, and the issue does NOT exist with esbuild either. - If the existing
.js.mapfile is invalidated in some way (syntax errors, invalid characters) it will discard it and generate a fresh, correct map file as expected.