swc-node icon indicating copy to clipboard operation
swc-node copied to clipboard

Source maps broken since versions 1.10.1 (up to and including latest 1.10.9)

Open pasieronen opened this issue 1 year ago • 5 comments

With version 1.10.0 this works as expected, and stack trace says test.ts:1:7 (which is correct):

npm i @swc-node/[email protected] 
echo "throw new Error()" > test.ts
node -r @swc-node/register test.ts

With version 1.10.1, the stack trace says test.ts:2:7.

It looks like the change related to inlineSourceMap in #726 broke the non-inline case. Maybe this line changed in #726

sourcemap: options.sourceMap || options.inlineSourceMap ? 'inline' : Boolean(options.sourceMap),

should have been instead something like this?

sourcemap: options.inlineSourceMap ? 'inline' : Boolean(options.sourceMap)

...so we get non-inline source maps by default. At least with Node 20.17.0 the inline source maps don't seem to work without the fix suggested in #791.

pasieronen avatar Aug 22 '24 16:08 pasieronen

Can confirm it's an issue - a workaround is to set inlineSourceMap: true in tsconfig.json instead of sourceMap: true if you're using TypeScript.

KidkArolis avatar Sep 25 '24 14:09 KidkArolis

The workaround does not work for me. Stack traces are always broken for me when source maps are inline. I opened a new issue to report this: #861.

maxfliri avatar Oct 24 '24 16:10 maxfliri

I'm running into this when using @swc/jest. Source maps are off when the input file has type declarations and other omittable material.

mctrafik avatar Feb 18 '25 20:02 mctrafik

I'm having a similar problem. Using v1.10.10 (and other versions—I've tried as far back as 1.9), blank lines are not handled properly by sourcemaps, so the line numbers reported in stack traces are always off. In larger files, they can be way off.

@Brooooooklyn any thoughts here?

mhamann avatar Apr 22 '25 18:04 mhamann

Same here. Using v1.10.10. This makes me mad. It is very hard to debug the code.

erayhanoglu avatar Aug 01 '25 07:08 erayhanoglu