Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ahuigo opened this issue Aug 17, 2022 · 9 comments
Labels

Comments

@ahuigo
Copy link

ahuigo commented Aug 17, 2022

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
    }
  ]
}

  1. second step: write demo.ts
  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:https://127.0.0.1:9229/ws/153d75ee-906d-465c-b05e-d9d48dca5437
Visit chrome:https://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: 
  [email protected]
  [email protected]
@ross-weir
Copy link

ross-weir commented Feb 28, 2023

+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
Copy link

sigmaSd commented Apr 16, 2023

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

@sigmaSd
Copy link

sigmaSd commented Apr 16, 2023

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

@bartlomieju
Copy link
Member

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

@sigmaSd
Copy link

sigmaSd commented Jul 13, 2023

The same reproduction steps still produce the same error deno 1.35.1

@ahuigo
Copy link
Author

ahuigo commented Jul 14, 2023

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: [email protected]

@bartlomieju bartlomieju added bug Something isn't working needs investigation and removed needs info labels Jul 26, 2023
@captainbuckkets
Copy link

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

@deer
Copy link

deer commented Jan 24, 2024

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
Copy link

mcgear commented Feb 18, 2024

I am getting the same error trying to use:

export { transpile } from "https://deno.land/x/[email protected]/mod.ts";

Deno 1.40.5
Deno extension v3.33.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants