swc-project / swc-node

Faster ts-node without typecheck
MIT License
1.8k stars 75 forks source link

Incorrect stack traces with inline sourceMaps #861

Open maxfliri opened 5 days ago

maxfliri commented 5 days ago

With swc-node v1.10.9, stack traces report incorrect line numbers when swc is configured to generate inline sourceMaps.

This happens with SWCRC=true when .swcrc has "sourceMaps": "inline". It also happens always when running without SWCRC=true, because this always results in inline sourceMaps, as reported in #848.

I get correct stack traces only when I use SWCRC=true and .swcrc has "sourceMaps": true.

maxfliri commented 5 days ago

I think the reason might be that sourcemaps are not added to SourcemapMap when inline.

Sourcemaps are added to SourcemapMap in the function below, which handles non-inline sourcemaps. As far as I can this is not happening for inline sourcemaps.

https://github.com/swc-project/swc-node/blob/fca85bd1ba1705455ca8c7adb345690cb029b4d3/packages/register/register.ts#L21-L37