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

ReferenceError: WebAssembly is not defined #686

Closed
oroppas opened this issue Dec 12, 2022 · 4 comments
Closed

ReferenceError: WebAssembly is not defined #686

oroppas opened this issue Dec 12, 2022 · 4 comments

Comments

@oroppas
Copy link

oroppas commented Dec 12, 2022

It appears WebAssembly.Memory is supported

void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {

but the following lines failed. Do I miss something obvious?

[ryuta@fedora cowasm]$ ~/packages/graalvm/bin/npx --experimental-options --js.webassembly --polyglot --jvm python-wasm@latest
OpenJDK VM warning: the use of signal() and sigset() for signal chaining was deprecated in version 16.0 and will be removed in a future release. Use sigaction() instead.
/home/ryuta/.npm/_npx/a6b69408c769c0a5/node_modules/@cowasm/kernel/dist/wasm/worker/import.js:57
    const memory = new WebAssembly.Memory({
                       ^

ReferenceError: WebAssembly is not defined
    at doWasmImport (/home/ryuta/.npm/_npx/a6b69408c769c0a5/node_modules/@cowasm/kernel/dist/wasm/worker/import.js:57:24)
    at debounced (/home/ryuta/.npm/_npx/a6b69408c769c0a5/node_modules/@cowasm/kernel/dist/wasm/reuseInFlight.js:35:37)
    at wasmImportNode (/home/ryuta/.npm/_npx/a6b69408c769c0a5/node_modules/@cowasm/kernel/dist/wasm/worker/node.js:96:18)
    at async createSyncKernel (/home/ryuta/.npm/_npx/a6b69408c769c0a5/node_modules/@cowasm/kernel/dist/kernel/kernel.js:17:27)
    at async syncKernel (/home/ryuta/.npm/_npx/a6b69408c769c0a5/node_modules/@cowasm/kernel/dist/kernel/node.js:48:26)
    at async createPython (/home/ryuta/.npm/_npx/a6b69408c769c0a5/node_modules/python-wasm/dist/node.js:50:17)
    at async syncPython (/home/ryuta/.npm/_npx/a6b69408c769c0a5/node_modules/python-wasm/dist/node.js:25:19)
    at async main (/home/ryuta/.npm/_npx/a6b69408c769c0a5/node_modules/python-wasm/dist/node-terminal.js:20:26)
@clemorej
Copy link

Try adding this to your environment variable:

NODE_OPTIONS=--polyglot
NODE_POLYGLOT_OPTIONS=--js.webassembly --experimental-options

@oroppas
Copy link
Author

oroppas commented Dec 12, 2022

Thanks for the tip! It worked albeit it took about 5 min or so and node allocated about 53 GB of memory at peak.

[ryuta@fedora cowasm]$ NODE_OPTIONS='--polyglot' NODE_POLYGLOT_OPTIONS='--js.webassembly --experimental-options'  ~/packages/graalvm/bin/npx python-wasm@latest
[To redirect Truffle log output to a file use one of the following options:
* '--log.file=<path>' if the option is passed using a guest language launcher.
* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.
* Configure logging using the polyglot embedding API.]
[java] WARNING: Disabling multi-threading since the context seems to contain single-threaded languages: [python, wasm, js]
[java] WARNING: Thread.start() called on java.lang.ref.Reference$ReferenceHandler / Reference Handler but thread support is disabled: context seems to contain single-threaded languages: [python, wasm, js]
[java] WARNING: Thread.start() called on java.lang.ref.Finalizer$FinalizerThread / Finalizer but thread support is disabled: context seems to contain single-threaded languages: [python, wasm, js]
[To redirect Truffle log output to a file use one of the following options:
* '--log.file=<path>' if the option is passed using a guest language launcher.
* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.
* Configure logging using the polyglot embedding API.]
[java] WARNING: Disabling multi-threading since the context seems to contain single-threaded languages: [python, wasm, js]
[java] WARNING: Thread.start() called on java.lang.ref.Reference$ReferenceHandler / Reference Handler but thread support is disabled: context seems to contain single-threaded languages: [python, wasm, js]
[java] WARNING: Thread.start() called on java.lang.ref.Finalizer$FinalizerThread / Finalizer but thread support is disabled: context seems to contain single-threaded languages: [python, wasm, js]
OpenJDK VM warning: the use of signal() and sigset() for signal chaining was deprecated in version 16.0 and will be removed in a future release. Use sigaction() instead.
Python 3.11.0 (main, Nov 29 2022, 20:26:05) [Clang 15.0.3 (git@github.com:ziglang/zig-bootstrap.git 0ce789d0f7a4d89fdc4d9571 on wasi
Type "help", "copyright", "credits" or "license" for more information.
>>> 

@woess
Copy link
Member

woess commented Apr 17, 2024

WebAssembly should work out-of-the-box in GraalNodeJS now, i.e. since 24.0.0.
I can confirm that npx python-wasm@latest now works, albeit it's very slow to start as you've noticed. We should investigate why. Most likely this can be improved significantly.
As for the original issue, I consider this fixed.

@woess
Copy link
Member

woess commented Apr 24, 2024

I've looked into why it's so slow and found 2 performance issues in the JS↔WASM interface, fixed in edbfa8e.
It should start up much faster now, within seconds not minutes.

@woess woess closed this as completed Apr 24, 2024
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