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

Consider releasing a version that does not require a bundler to the npm registry #6

Open
GarciaLnk opened this issue Mar 19, 2023 · 8 comments
Labels
enhancement New feature or request

Comments

@GarciaLnk
Copy link

Right now, it's impossible to use the library directly from npm without using a bundler like Webpack, consider releasing a build using the --target web flag to allow using it without a bundler, or with bundlers that don't properly support WASM yet (like Parcel v2).

@DawChihLiou
Copy link
Contributor

Hey @GarciaLnk, thanks for your suggestion! I'll explore the options. At the meantime, you can directly import the .wasm file to start using it without a bundler. For example:

// cjs
const voy = require("voy-search/voy_search_bg.wasm");

// or esm
const voy = await import("voy-search/voy_search_bg.wasm");

@DawChihLiou DawChihLiou added the enhancement New feature or request label Mar 20, 2023
@GarciaLnk
Copy link
Author

AFAIK to import a WASM module as a native ES module you need a bundler that has proper support for it, which is the root of the issue (see: https://rustwasm.github.io/docs/wasm-bindgen/reference/deployment.html#bundlers).

@wonderwhy-er
Copy link

wonderwhy-er commented Mar 30, 2023

Wanted to test it quickly by loading from CDN trough unpkg
https://www.unpkg.com/browse/[email protected]/

So I could add script tag to a html page like this:
<script src="https://www.unpkg.com/[email protected]/voy_search.js" type="module"></script>

That results in an error:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/wasm". Strict MIME type checking is enforced for module scripts per HTML spec.

As far as I understand direct importing of wasm modules is not supported yet

I did manage to make it work with this code

import * as voy from 'https://www.unpkg.com/[email protected]/voy_search_bg.js';
WebAssembly.instantiateStreaming(fetch("https://www.unpkg.com/[email protected]/voy_search_bg.wasm"), {
    "./voy_search_bg.js": voy,
    },
}).then((module) => {
    voy.__wbg_set_wasm(module.instance.exports);
});

Sadly later trying to load my embeddings got an err:
image

@DawChihLiou
Copy link
Contributor

@wonderwhy-er thanks so much for reporting. Could you attach your embeddings or show me how did you generate them so I can reproduce the error? Thanks!

@wonderwhy-er
Copy link

Ouh its my bad, it seems to work.
I was using TensorFlow JS universal sentence encoder
https://github.com/tensorflow/tfjs-models/blob/master/universal-sentence-encoder/README.md

And for whatever reasons in some cases it returns [number[]] instead of number[] for encoding
I did Array.flat() on it and then it all worked!

@DawChihLiou
Copy link
Contributor

Amazing! Have fun:)

@DawChihLiou DawChihLiou mentioned this issue Apr 11, 2023
@MentalGear
Copy link

Hey @wonderwhy-er I'm also looking to get voy work in the browser, potentially with up to 1GB or records. Would you be able to share your wasm solution?

@wonderwhy-er
Copy link

@MentalGear sorry missed your question, I since then switched to using other things
My code was kinda like this https://jsfiddle.net/wonderwhy_er/k4bwLf2e/31/
But it does not work in jsfiddle and I do not have original code I had working anymore

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

No branches or pull requests

4 participants