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

WebAssembly.Compile is disallowed on the main thread, if the buffer size is larger than 4KB. #74

Open
motorina0 opened this issue Feb 3, 2022 · 5 comments
Labels

Comments

@motorina0
Copy link
Member

Currently the WebAssembly part is loaded synchronously:

const mod = new WebAssembly.Module(binary);
const instance = new WebAssembly.Instance(mod, imports);

This results in the following error:
WebAssembly.Compile is disallowed on the main thread, if the buffer size is larger than 4KB. Use WebAssembly.compile, or compile on a worker thread.

However the async version of the methods cannot be run on the top-level file AFAIK.
Any ideas how to fix this?

@junderw
Copy link
Member

junderw commented Feb 4, 2022

Can you provide detailed repro steps?

@junderw
Copy link
Member

junderw commented Feb 6, 2022

I think this is a browser error... but that file is not used in browsers.

wasm_loader.browser.ts is for browsers.

Either:

  1. It's an error in whatever bundler you used.
  2. Maybe there's some weird edge case in NodeJS... in which case I need better repro steps.

@motorina0
Copy link
Member Author

  1. It's an error in whatever bundler you used.

It is an Electron app that uses the lib, it might be the bundler. I will have a more in detail look. Thank you for the hint.

@pxr64
Copy link

pxr64 commented Mar 29, 2023

Facing the same issue.

I ended up creating a fork and updating the browser loader.
src_ts
/wasm_loader.browser.ts

// Suppress TS2792: Cannot find module './secp256k1.wasm'.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import wasm from "./secp256k1.wasm";

import * as rand from "./rand.js";
import * as validate_error from "./validate_error.js";
const imports = {
    "./rand.js": rand,
    "./validate_error.js": validate_error,
};
const mod = await WebAssembly.compile(Buffer.from(wasm.split(',')[1], 'base64'));
const instance = await WebAssembly.instantiate(mod, imports);

export default instance.exports;

@Taha-daboussi
Copy link

hey @motorina0 ,
I know it's been long time since this issue was opened , just checking if you was able to solve this error

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

4 participants