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

Failed to parse URL to /path/to/monero_wallet_full.wasm #205

Open
woodser opened this issue Apr 19, 2024 · 1 comment
Open

Failed to parse URL to /path/to/monero_wallet_full.wasm #205

woodser opened this issue Apr 19, 2024 · 1 comment

Comments

@woodser
Copy link
Owner

woodser commented Apr 19, 2024

Currently, loading the .wasm files will fail in Node.js >16 or Next.js with the error:

"Failed to parse URL from /path/to/monero-ts/dist/dist/monero_wallet_full.wasm"

This is because the new fetch API does not support loading local files, as done here:

if (LibraryUtils.WASM_MODULE) return LibraryUtils.WASM_MODULE;

And here:

let module = await require("../../../../dist/monero_wallet_full")();

A workaround in Node.js is to pass --no-experimental-fetch to node, but this doesn't work Next.js apps.

This issue requests updating monero-ts to load the .wasm files which works with the new fetch API.

For proof of concept, the fix should work in the sample Next.js app, and the --no-experimental-fetch flag should no longer be needed.

See related issue #180 for more commentary.

@woodser woodser changed the title Failed to parse URL to Failed to parse URL to /path/to/monero_wallet_full.wasm Apr 19, 2024
@mainnet-pat
Copy link

Might be a viable option until the next emscription PR is ready.

Copy of my message from earlier in matrix:

diff --git a/node_modules/monero-ts/dist/src/main/ts/common/LibraryUtils.js b/node_modules/monero-ts/dist/src/main/ts/common/LibraryUtils.js
index 30c4052..86ebd61 100644
--- a/node_modules/monero-ts/dist/src/main/ts/common/LibraryUtils.js
+++ b/node_modules/monero-ts/dist/src/main/ts/common/LibraryUtils.js
@@ -86,7 +86,10 @@ class LibraryUtils {
     if (LibraryUtils.WASM_MODULE) return LibraryUtils.WASM_MODULE;
 
     // load module
+    const fetch_ = globalThis.fetch;
+    globalThis.fetch = undefined; // prevent fetch in worker
     let module = await require("../../../../dist/monero_wallet_keys")();
+    globalThis.fetch = fetch_;
     LibraryUtils.WASM_MODULE = module;
     delete LibraryUtils.WASM_MODULE.then;
     LibraryUtils.initWasmModule(LibraryUtils.WASM_MODULE);
@@ -106,7 +109,10 @@ class LibraryUtils {
     if (LibraryUtils.WASM_MODULE && LibraryUtils.FULL_LOADED) return LibraryUtils.WASM_MODULE;
 
     // load module
+    const fetch_ = globalThis.fetch;
+    globalThis.fetch = undefined; // prevent fetch in worker
     let module = await require("../../../../dist/monero_wallet_full")();
+    globalThis.fetch = fetch_;
     LibraryUtils.WASM_MODULE = module;
     delete LibraryUtils.WASM_MODULE.then;
     LibraryUtils.FULL_LOADED = true;

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

2 participants