You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code调试Node.js TypeScript无法设置断点求助

Fixing Unbreakable Breakpoints in VS Code Node.js TypeScript Attach Debugging

Hey there, I’ve been in your shoes before—successfully attaching the debugger but being stuck with unresponsive breakpoints and no way to step through code is super frustrating. Let’s walk through the most common fixes for this issue:

1. Verify Your Source Map Setup First

Source maps are the bridge between your compiled JS files and TypeScript source code, so if they’re missing or misconfigured, breakpoints won’t link up.

  • Double-check your tsconfig.json has "sourceMap": true enabled.
  • Make sure your "outDir" in tsconfig.json matches the path in outFiles from your launch config (e.g., if outDir is "./build", your outFiles should target that folder).
  • After compiling, open one of your built JS files—you should see a comment like //# sourceMappingURL=your-file.js.map at the top. If not, re-run tsc to regenerate source maps.

2. Fix the outFiles Path Variable

${workspaceRoot} is an older VS Code variable; the current recommended one is ${workspaceFolder}. Update your launch config to use this to avoid path resolution issues:

"outFiles": ["${workspaceFolder}/build/**/*.js"]

Also, confirm the path exactly matches where your compiled JS files live—if your code compiles to build/src instead of just build, adjust the path to ${workspaceFolder}/build/src/**/*.js.

3. Add skipFiles to Avoid Interference

Node.js internal modules and third-party dependencies can sometimes throw off the debugger. Adding this line to your config will tell VS Code to ignore those files, keeping focus on your code:

"skipFiles": ["<node_internals>/**", "node_modules/**"]

4. Manually Validate Breakpoint Paths

If your breakpoint appears grayed out, VS Code can’t map it to the correct source file. Right-click the breakpoint, select Edit Breakpoint, and check if the auto-generated path matches your actual TypeScript file location. If not, manually enter the correct relative path to your TS file.

5. Clear Cache & Rebuild

Sometimes stale builds or debugger cache cause issues:

  • Stop the debugging session entirely.
  • Delete your build folder (or whatever your output directory is).
  • Recompile your TypeScript with tsc.
  • Restart the Node.js process you’re attaching to, then re-launch the debugger.

6. Check Node.js Version

Older Node.js versions (pre-v10) have limited source map support for attach debugging. Upgrade to an LTS version (v16+ or v18+) if you’re running an older release.

Example Updated Launch Config

Here’s how your launch.json should look after applying these fixes:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Attach",
      "port": 5858,
      "sourceMaps": true,
      "outFiles": ["${workspaceFolder}/build/**/*.js"],
      "skipFiles": ["<node_internals>/**", "node_modules/**"]
    }
  ]
}

One last thing: Ensure your tsconfig.json has "rootDir" set to your TypeScript source directory (e.g., "rootDir": "./src"). This ensures source maps generate accurate paths linking back to your original TS files.

内容的提问来源于stack exchange,提问作者Joshua Ohana

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:41:45