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

Fail to load WASM error #35

Open
brendantwy opened this issue Mar 27, 2023 · 8 comments
Open

Fail to load WASM error #35

brendantwy opened this issue Mar 27, 2023 · 8 comments

Comments

@brendantwy
Copy link

brendantwy commented Mar 27, 2023

Heya, I am currently facing this error when calling FastText.loadWASM():

TypeError: Failed to parse URL from /home/brendan/internal-sourcing-tool/node_modules/fasttext.js/lib/wasm/fasttext_wasm.wasm
/home/brendan/internal-sourcing-tool/node_modules/fasttext.js/lib/wasm/fasttext_wasm.js:230
      throw ex;
      ^

RuntimeError: abort(TypeError: Failed to parse URL from /home/brendan/internal-sourcing-tool/node_modules/fasttext.js/lib/wasm/fasttext_wasm.wasm) at Error
    at jsStackTrace (/home/brendan/internal-sourcing-tool/node_modules/fasttext.js/lib/wasm/fasttext_wasm.js:1937:19)
    at stackTrace (/home/brendan/internal-sourcing-tool/node_modules/fasttext.js/lib/wasm/fasttext_wasm.js:1954:16)
    at process.abort (/home/brendan/internal-sourcing-tool/node_modules/fasttext.js/lib/wasm/fasttext_wasm.js:1653:44)
    at process.emit (node:events:513:28)
    at emit (node:internal/process/promises:149:20)
    at processPromiseRejections (node:internal/process/promises:283:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:32)
    at process.abort (/home/brendan/internal-sourcing-tool/node_modules/fasttext.js/lib/wasm/fasttext_wasm.js:1659:11)
    at process.emit (node:events:513:28)
    at emit (node:internal/process/promises:149:20)
    at processPromiseRejections (node:internal/process/promises:283:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:32)

Node.js v18.15.0

Below is my code snippet, following the example given in this issue:

async function main() {
    const modelPath = path.resolve(__dirname, "../model");
    console.log(modelPath + `/300-dim-10-epoch.bin`);
    let FastText = require("fasttext.js");
    const ft =  new FastText({
        loadModel: modelPath + `/300-dim-10-epoch.bin`
    })
    try {
        await ft.loadWASM();
        const vec = ft.getWordVector("hello");
        console.log(vec);
    }catch(err){
        console.log(err);
    }
}

main();

There is no issues with my model directory and I tried running the snippet via the npm install package and git clone installation method.

@brendantwy
Copy link
Author

brendantwy commented Mar 27, 2023

Update

So apparently changing the current node version from 18.15.0 to 16.19.1 fixed it. No idea how node versions affect the lib.

Edit

Found the cause. Node 18 contains a new experimental fetch API. Disabling it with --no-experimental-fetch flag works as well

Sidenote

If your .bin model file is > 2Gb using the native fasttext wasm functions to load said model will fail. Very unfortunate :(

@loretoparisi
Copy link
Owner

loretoparisi commented Mar 29, 2023

amazing finding, thank you! I actually had the same error when released the last update few days ago, while the problem of 2GB is well-known due to Wasm 32bit architecture. Wasm 64bit is a work in progress and it should come in 2023.
I will investigate a bit more node 18 and WASM and update the README.md

@sneljo1
Copy link

sneljo1 commented Jun 7, 2023

Also having this issue regardless of node version. Also, the model used is very small so should also not be an issue. Seems to complain just when even only importing the module

@loretoparisi
Copy link
Owner

@sneljo1 do you have the error log from wasm module init?

@nemphys
Copy link

nemphys commented Jun 8, 2024

Downgrading to Node 16/18 in 2024 is not a viable option anymore, and the error is still there with Node 20.
Is there a change that a proper solution is found for this issue?

@loretoparisi
Copy link
Owner

Downgrading to Node 16/18 in 2024 is not a viable option anymore, and the error is still there with Node 20.

Is there a change that a proper solution is found for this issue?

agreed, it should work on node ETS. I will investigate a bit more. There were some underlying changes in the WASM ABI and wasm modules support since Node 18 that requires some work.

@nemphys
Copy link

nemphys commented Jun 8, 2024

After commenting out

FastTextWasm = require('./wasm/fasttext')

everything seems to work fine, since wasm is not needed in my case, maybe it should be initialized only when needed.

@RodolfoGS
Copy link

Thanks @nemphys, that worked. Also I created a patch to remove FastTextWasm

diff --git a/node_modules/fasttext.js/lib/index.js b/node_modules/fasttext.js/lib/index.js
index a7a7b01..5fd90f8 100644
--- a/node_modules/fasttext.js/lib/index.js
+++ b/node_modules/fasttext.js/lib/index.js
@@ -12,8 +12,7 @@
         path = require('path'),
         os = require('os'),
         Util = require('./util'),
-        Deque = require('./deque'),
-        FastTextWasm = require('./wasm/fasttext');
+        Deque = require('./deque');
 
     var FastText;
     FastText = (function () {

Note: With this patch you can't use loadWASM

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

5 participants