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

import() is disallowed on ServiceWorkerGlobalScope by the HTML specification. #8

Open
davidtbo opened this issue Jul 8, 2023 · 3 comments

Comments

@davidtbo
Copy link

davidtbo commented Jul 8, 2023

Hello,

I'm trying to use your package to run hnswlib in a Chrome extension's background script. When I call loadHnswlib I get the error:

import() is disallowed on ServiceWorkerGlobalScope by the HTML specification.

Note that I don't get this error when importing transformers.js and it's successfully working in the background script, so it's not generally failing to do imports.

Any idea why your module might be different? I'm stumped why one module would import and work but not another, given this error message.

@clmnin
Copy link

clmnin commented Jul 11, 2023

The reason you have this error is because @ShravanSunder is doing a dynamic import here

const temp = await import('./hnswlib.mjs');

Browser extension service workers do not support dynamic import - source

There are two methods of importing scripts into a service worker: the import statement and the importScripts() method. Note that import(), often called a dynamic import, is not supported.

I'm also building a browser extension and needed a faster vector search approach (instead of my linear O(n) search) - https://twitter.com/clamentjohn/status/1678096766204248067

@ShravanSunder
Copy link
Owner

ShravanSunder commented Jul 12, 2023

Currently the library doesn't support workers. Its not something i've looked into on how to load wasm files into service workers.

we'll have to use fetch and a relative or remote url to load wasm into a serviceworker.

@ShravanSunder
Copy link
Owner

ShravanSunder commented Jul 12, 2023

Feel free to make a PR. Just make sure to add tests, that all tests pass and follow the same code convention. 😄

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