Skip to content

Use sqlite-wasm-rs with web workersΒ #64

@LucaCappelletti94

Description

@LucaCappelletti94

Hi,

I am trying to use sqlite-wasm-rs as part of a Yew web worker.

This web worker, which is called dbws_worker, is imported in Trunk using the following trunk metadata link:

<link data-trunk rel="rust" href="Cargo.toml" data-bin="dbws_worker" data-type="worker" data-bindgen-target="web" data-weak-refs
    data-wasm-opt="z" />

Now, when I start the application, depending on the browser, I get a few different errors:

In Google Chrome, I get: Uncaught SyntaxError: Failed to execute 'importScripts' on 'WorkerGlobalScope': Cannot use import statement outside a module, which is associated to the following line which gets added to the top of the web worker script:

import { JSUtils } from './snippets/sqlite-wasm-rs-56a7e97fd7d8f783/src/vfs/utils.js';

As illustrated here:

Image

In Safari, I get SyntaxError: Unexpected token '{'. import call expects one or two arguments., but I don't know the line of the error so I am not certain it is related to sqlite-wasm-rs - it is co-occurrent with when I import it though.

Finally, in Firefox I get SyntaxError: import declarations may only appear at top level of a module, which is also referring to the same line as in Google Chrome.

The overall application looks something like this:

Image

If needed, I can try to reduce this to a smaller test example - do let me know whether these information have already given you some ideas to try out.

Have a great day and thank you,
Luca

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions