为 Deno 设置用于调试的 VS Code 配置文件 launch.json

Deno 支持 V8 的调试协议,因此可以很轻松的在 Chrome Devtools 和 VS Code 中进行调试。

当在 VS Code 中调试 Deno 时,我们可以直接使用 VS Code 内置的 Node.js debuggger。对应的 launch.json 文件如下:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Deno",
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "runtimeExecutable": "deno",
      "runtimeArgs": ["run", "--inspect-brk", "-A", "${file}"],
      "port": 9229
    }
  ]
}

**注:**用你项目中的真实文件地址替换掉上文的 ${file}

3 个赞

遇到一个问题,提到 issue 里了

ry 说他不能复现 :joy:
大家能帮我试试在你那儿能不能复现吗?

代码:

// a.ts
import * as ts from 'https://dev.jspm.io/typescript@3.9.3';
console.log(ts.default.transpileModule('const foo: number = 1;', {}).outputText);

.vscode/launch.json 配置:

{
  "version": "0.2.0",
  "configurations": [
    {
      "env": {
        "RUST_BACKTRACE": "full"
      },
      "name": "Deno",
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "runtimeExecutable": "deno",
      "runtimeArgs": ["run", "--inspect-brk", "-A", "a.ts"],
      "port": 9229
    }
  ]
}

然后在 vscode 中运行调试工具,预期会报错:

/Users/xcatliu/.deno/bin/deno run --inspect-brk -A a.ts 
Debugger listening on ws://127.0.0.1:9229/ws/118bc875-11b7-43b2-8b0a-30baa323b8ad
Debugger session started.
thread 'main' panicked at 'already borrowed: BorrowMutError', /rustc/49cae55760da0a43428eba73abcb659bb70cf2e4/src/libcore/cell.rs:878:9
stack backtrace:
   0:        0x110d7e9bf - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h83d53b696ac99295
   1:        0x110daadfe - core::fmt::write::hf81c429634e1f3ed
   2:        0x110d75917 - std::io::Write::write_fmt::had2a3b01a2c037b5
   3:        0x110d8100a - std::panicking::default_hook::{{closure}}::ha991e4eca34b4afa
   4:        0x110d80d4c - std::panicking::default_hook::h722aa3f5c1c31788
   5:        0x110d815d8 - std::panicking::rust_panic_with_hook::h2cd47f71d6d55501
   6:        0x110d811a2 - rust_begin_unwind
   7:        0x110dd595f - core::panicking::panic_fmt::h299f54c72477a62a
   8:        0x110dd5865 - core::result::unwrap_failed::hf7a9e1e19e331f17
   9:        0x1101dd1c6 - deno_core::bindings::send::h9bde1f22d54f964b
  10:        0x1101bf4ad - <extern "C" fn(A0) .> R as rusty_v8::support::CFnFrom<F>>::mapping::c_fn::h184c60d18e8b8431
  11:        0x11025eb4f - _ZN2v88internal25FunctionCallbackArguments4CallENS0_15CallHandlerInfoE
  12:        0x11025e061 - _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEESA_NS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EENS0_16BuiltinArgumentsE
  13:        0x11025d6d1 - _ZN2v88internalL26Builtin_Impl_HandleApiCallENS0_16BuiltinArgumentsEPNS0_7IsolateE
fatal runtime error: failed to initiate panic, error 5

虽然我想尝试一下,但 dev.jspm.io 阻止了我 图片

试了,确实没有复现

现在debugger好像是会出问题,VSCODE的原因,大佬有解决方案吗

是调试协议的问题,我正在查

好的,有新的解决方案,求告知,谢谢!

你可以关注这个 issue