denoland / vscode_deno

Visual Studio Code plugin for Deno
https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno
MIT License
1.47k stars 141 forks source link

debug wasm: Uncaught TypeError: WebAssembly.compile(): Argument 0 must be a buffer source #708

Open ahuigo opened 2 years ago

ahuigo commented 2 years ago

Describe the bug Debug wasm within Vscode will throw this error:

Debugger session started.
Debugger session ended
error: Uncaught TypeError: WebAssembly.compile(): Argument 0 must be a buffer source

When I debug it within chrome, it works well:

$ deno run -A --inspect --inspect-brk demo.ts

So, I guess that the deno plugin for vscode may have a bug.

To Reproduce Here is a bad case example : https://github.com/ahuigo/deno-debug-example.

  1. first step: config vscode's .vscode/launch.json
    
    {
    "version": "0.2.0",
    "configurations": [
    {
      "request": "launch",
      "name": "debug wasm",
      "type": "pwa-node",
      "program": "${workspaceFolder}/demo.ts",
      "cwd": "${workspaceFolder}",
      "runtimeExecutable": "deno",
      "args": ["--dev"],
      "runtimeArgs": [
        "run",
        "--inspect",
        "--inspect-brk",
        "-A"
      ],
      "smartStep": false,
      "attachSimplePort": 9229
    }
    ]
    }
2. second step: write demo.ts
```js
  const imports= { imports: { imported_func: (arg) => console.log(arg) } };
  const wasmCode = new Uint8Array([
    0, 97, 115, 109, 1, 0, 0, 0, 1, 133, 128, 128, 128, 0, 1, 96, 0, 1, 127,
    3, 130, 128, 128, 128, 0, 1, 0, 4, 132, 128, 128, 128, 0, 1, 112, 0, 0,
    5, 131, 128, 128, 128, 0, 1, 0, 1, 6, 129, 128, 128, 128, 0, 0, 7, 145,
    128, 128, 128, 0, 2, 6, 109, 101, 109, 111, 114, 121, 2, 0, 4, 109, 97,
    105, 110, 0, 0, 10, 138, 128, 128, 128, 0, 1, 132, 128, 128, 128, 0, 0,
    65, 42, 11
  ]);
  const res=new Response(wasmCode, {headers: [["Content-Type", "application/wasm"]]})
  const r = await WebAssembly.instantiateStreaming(res,imports)
  console.log(r)
  1. Start debugging with F5
    deno run --inspect --inspect-brk -A ./demo.ts --dev
    Debugger listening on ws://127.0.0.1:9229/ws/153d75ee-906d-465c-b05e-d9d48dca5437
    Visit chrome://inspect to connect to the debugger.
    Deno is waiting for debugger to connect.
    Debugger session started.
    Debugger session ended
    error: Uncaught TypeError: WebAssembly.compile(): Argument 0 must be a buffer source

Expected behavior Not throw any error. (When I debug it within chrome, it works well)

Versions I tried both deno 1.23.1 and deno 1.24.3, same error:

....
Debugger session started.
Debugger session ended
error: Uncaught TypeError: WebAssembly.compile(): Argument 0 must be a buffer source

My environment

macOsx: 12.3.1
cpu: Darwin 21.4.0 arm64 core(10) Apple M1 Pro
vscode: 1.68.1 30d9c6cd9483b2cc586687151bcbcd635f373630 arm64
deno 1.24.3 (release, aarch64-apple-darwin)
v8 10.4.132.20
typescript 4.7.4
deno extensions: 
  denoland.vscode-deno@3.13.1
  laurencebahiirwa.deno-std-lib-snippets@0.0.8
ross-weir commented 1 year ago

+1 on this issue

$ deno --version
deno 1.30.1 (release, x86_64-pc-windows-msvc)
v8 10.9.194.5
typescript 4.9.4

Extension version: v3.17.0

Same setup and error, same observations where debugging works in chrome but fails in vscode

sigmaSd commented 1 year ago

The same happen (in nvim) with another implementation https://github.com/mfussenegger/nvim-dap

sigmaSd commented 1 year ago

Maybe the issue lies in https://github.com/microsoft/vscode-js-debug

bartlomieju commented 1 year ago

Hey folks, sorry for a slow response. Do you still experience the same issue with latest Deno?

sigmaSd commented 1 year ago

The same reproduction steps still produce the same error deno 1.35.1

ahuigo commented 1 year ago

Same error with with deno 1.33.4, here is an example: https://github.com/ahuigo/deno-debug-example.

Bad case reproduce step:

  1. Install vscode and vscode-deno plugin.
  2. Open this project with vscode
  3. Press F5, then there will be an error like error: Uncaught TypeError: WebAssembly.compile(): Argument 0 must be a buffer source

This is tested by:

kernel: 21.6.0
os: macOSX 12.6
cpu: Darwin 21.6.0 arm64 core(10) Apple M1 Pro
vscode: 1.76.2 
deno 1.33.4 
v8 11.4.183.2
typescript 5.0.4
deno extensions: denoland.vscode-deno@3.19.1
captainbuckkets commented 10 months ago

+1 for this on Deno 1.37.1 with the same steps to reproduce as people above.

deer commented 7 months ago

I can easily reproduce this with the deno_graph project. When I open up https://github.com/denoland/deno_graph/blob/main/js/test.ts in vs code and click "run" on the first test I get:

running 1 test from ./js/test.ts
createGraph() ... ok (101ms)

ok | 1 passed | 0 failed | 21 filtered out (107ms)

But when I click "debug" I get:

running 1 test from ./js/test.ts
createGraph() ... FAILED (15ms)

 ERRORS 

createGraph() => ./js/test.ts:19:6
error: TypeError: WebAssembly.compile(): Argument 0 must be a buffer source
    at eventLoopTick (ext:core/01_core.js:182:7)

 FAILURES 

createGraph() => ./js/test.ts:19:6

FAILED | 0 passed | 1 failed | 21 filtered out (21ms)

This is annoying because I'm trying to use createGraph in fresh, but whenever I try to step past this call, the debugger fails.

mcgear commented 6 months ago

I am getting the same error trying to use:

export { transpile } from "https://deno.land/x/emit@0.37.0/mod.ts";

Deno 1.40.5 Deno extension v3.33.3

mcgear commented 1 month ago

I thought i'd throw a work around out there while this awaits resolution. If possible, wrap the call throwing this error in its own Worker, this throws the WebAssembly out on a separate thread, and make the rest of the app debug-able.