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

wasm-bindgen memory optimization seems to have broken the plugin #5

Closed
Secretmapper opened this issue Jul 4, 2022 · 4 comments
Closed

Comments

@Secretmapper
Copy link

Secretmapper commented Jul 4, 2022

Steps to reproduce:

  1. Do the wasm-pack tutorial
  2. Install Vite with this plugin
  3. Get error: Cannot access memory before initialization on the bg file. (Truncated below):
import * as wasm from '/-/hello-wasm/hello_wasm_bg.wasm?import';

let cachedUint8Memory0;
function getUint8Memory0() {
    if (cachedUint8Memory0.byteLength === 0) {
        cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
    }
    return cachedUint8Memory0;
}

cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); // Uncaught ReferenceError: Cannot access 'memory' before initialization

The memory checking seems to have been changed since this PR: rustwasm/wasm-bindgen#2886 and I'm guessing the initialization logic is different from what's now needed since the wasm file is referenced in the top level.

@Menci
Copy link
Owner

Menci commented Jul 5, 2022

Could you please test this WASM binding with Webpack5's asyncWebAssembly and check if Webpack 5 could handle this correctly?

@Secretmapper
Copy link
Author

@Menci I've tried to look into it, and in the process it seems like I should have checked the related issues of the one I linked - the bug seems to have been fixed by this PR:

rustwasm/wasm-bindgen#2965

Closing as it's a wasm-bindgen issue.

@0x1f57
Copy link

0x1f57 commented Jul 23, 2022

Could you please test this WASM binding with Webpack5's asyncWebAssembly and check if Webpack 5 could handle this correctly?

I tested that everything was normal in webpack5

@Menci
Copy link
Owner

Menci commented Jul 23, 2022

Yes, I also found that Webpack 5 could load buggy bindings successfully. But Node.js's native ESM WASM loader fails.

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

No branches or pull requests

3 participants