swc-project / swc-node

Faster ts-node without typecheck
MIT License
1.72k stars 71 forks source link

swc-node cannot triggered breakpoints correctly. #697

Closed hua03 closed 1 year ago

hua03 commented 1 year ago

This is my demo swc-node-debug-demo.

I used two ways to start the debugger, launch and attach. These ways is useless in Webstorm and VSCode.

There are two ways to set breakpoint, click on editor gutter (side area of line number) or use debugger grammar.


Test in Webstorm

Start Debugger by launch

repoduce:

  1. open package.json in the project
  2. click editor gutter same row as debug:swc-node, Then select debug 'debug:swc-node'
  3. visit http://localhost:3000 on browser.
  4. Then the program into the breakpoint, but it didn't stop at the right place. If you operate the debugger, it won't jump correctly.

If you delete debugger in the line six on app.ts, repeat the above steps, you will find the debugger does not stop at breakpoints.

Start Debugger by attach

repoduce:

  1. run command npm run attach:swc-node on Terminal, it will print debugger listening address
  2. click the address, webstorm will auto start debugger to attach to the program.
  3. then the terminal will print Debugger attached.
  4. visit http://localhost:3000 on browser. The debugger do not stop at breakpoints.


Test in VSCode

Start Debugger by launch

repoduce:

  1. open Run and Debug panel
  2. select the config debug:swc-node, and run it
  3. visit http://localhost:3000 on browser.
  4. vscode will open another compiled app.ts file in editor.

Start Debugger by attach

repoduce:

  1. run command npm run attach:swc-node on Terminal, it will print debugger listening address
  2. change the debug config attach:swc-node, update the field remoteRoot
  3. visit http://localhost:3000 on browser.
  4. vscode will open another compiled app.ts file in editor.



If start debugger with the script debug:ts-node, the debugger will trigger breakpoints correctly.

Brooooooklyn commented 1 year ago

Have you tried to set inlineSourceMap: true: https://github.com/hua03/swc-node-debug-demo/blob/main/tsconfig.json#L8

hua03 commented 1 year ago

If set inlineSourceMap: true, start the command debug:swc-node, it will report an error failed to open input source map file. debug:ts-node can start the app normally.

image

robbiespeed commented 1 year ago

@Brooooooklyn I noticed there was a bug where "inline" didn't get passed to swc when inlineSourceMap: true is set in tsconfig. Submitted a PR with simple fix that seemed to work for me when using @swc-node/register