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 build
to build an initialdist/index.js
anddist/index.js.map
- Make some changes in
index.ts
- Run
npm run build
again. - Note that
dist/index.js
has the updated changes, butdist/index.js.map
does 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:swc
script instead ofbuild
. - Also tested with
esbuild
usingbuild:esbuild
script, and the issue does NOT exist with esbuild either. - If the existing
.js.map
file is invalidated in some way (syntax errors, invalid characters) it will discard it and generate a fresh, correct map file as expected.