swc
swc copied to clipboard
Source maps aren't loaded correctly in Chrome Node DevTools
I ran node --inspect-brk -r @swc/register some_script.ts
and then opened chrome://inspect
- DevTools for Node. Source maps weren't loaded properly (was showing a transpiled JS content under a TS filename). I checked with babel and it works fine. There seems to be a difference between babel and swc that makes it break - I used debugger to dynamically modify swc source maps and managed to see it working.
It looks like embedding full filename path in sources doesn't work in Chrome DevTools for Node. What babel does, and seems to make it work - is encodes directory path in sourceRoot and just filename in sources.
This works (babel):
{
"version": 3,
"sourceRoot": "/Users/pbadenski/workspace/project/",
"sources": [
"test.ts"
],
...
}
This doesn't (swc):
{
"version": 3,
"sources": [
"/Users/pbadenski/workspace/project/test.ts"
],
...
}
Can you try https://swc.rs/docs/configuring-swc/#inlinesourcescontent ?
I tried, doesn't help unfortunately.
@kdy1 Just flagging that that this and similar source map issues are pretty serious obstacle for our team. We have recently switched all development to swc. We unfortunately might need to partially go back to babel because of difficulty with debugging and exception stack traces. I think it might be similar for other teams. I'm wondering whether you thought of giving these type of issues higher priority?
Do we know only chrome devtools affected by this or other tools are also broken? I recall in few tools (like jest?) saw correctly mapped source locations so curious if this is tool specifics.
Per spec,
If the sources are not absolute URLs after prepending of the “sourceRoot”, the sources are resolved relative to the SourceMap
I guess having each sources having full path without sourceroot would behave same. Maybe lacks of sourceRoot
property relates with this.
It seems to a bit of hit and miss. WebStorm works in some situations - but also had many issues and reports from my team that it frequently doesn't.
Curiousity q: if you manually add sourceRoot: ""
in existing sourcemap, does it makes any diff?
I have a similar report where source maps were working when debugging unit tests with VSCode but not WebStorm. I haven't had time to investigate that issue in particular but we pinned swc/core
to 1.2.100
because the source maps are broken in WebStorm in 1.2.101
.
The swc deps it works with:
"@swc-node/jest": "1.4.1",
"@swc/core": "1.2.100",
"swc-loader": "0.1.15",
@egilsster Can you try inlineSourcesContent: false
?
Judging from https://github.com/swc-project/swc/milestone/202?closed=1, and there's https://github.com/swc-project/swc/pull/2471 which changes the default behavior.
Tried (a variation of options with inlineSourcesContent
and sourceMaps
) with 118 and 119 just now in VSCode and neither is working correctly at the moment while babel-loader is working. Running Jest in a debugging terminal in VSCode and none of my breakpoints are hitting. Simply reporting back but don't have the bandwidth to investigate that issue right now. Will create an issue if I manage to get a repro up.
NOTE: I am using a project with swc packages only (not the swc-node variant):
"@swc/core": "1.2.119",
"@swc/jest": "0.2.14",
"swc-loader": "0.1.15",
It looks like there are multiple different roots to investigate (from @swc/register
to something else). Anyone experiencing this issue mind share exact repro steps for each? It's hard to do guesswork with currently known information.
Just FYI looks, I'm extremely happy. I haven't had any problems since recently - I will keep this thread updated. Thank you!! :star:
Can you try the latest version of @swc/core
? (v1.2.155
)
Patches in https://github.com/swc-project/swc/pull/4007 are very likely to fix this issue.
Can anyone make an executable repro case? node.js seems to consume sourcemap of swc without any problem.
See https://github.com/kdy1/swc/tree/6cea544afa481e063cff6d8d493d8d12dadb280a/crates/swc/tests/stacktrace for exmaple repro case.
Can you try the latest version? (v1.2.156
)
There was a bug fix for a module that only contains export * from './foo'
and such module is super common, so I think it can be the cause of this.
If it helps, I'm still having the same issue and was able to create a quick repo to reproduce it: https://github.com/daviduzumeri/swctest
Any help would be appreciated, as we're pretty much back to console.log
debugging over here.
I found that sourcemap
crate does not support sourceRoot
.
https://docs.rs/sourcemap/6.1.0/sourcemap/struct.SourceMapBuilder.html
Ref: https://github.com/getsentry/rust-sourcemap/issues/50
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.