How to use DuckDB browser wasm module without bundler?

4 days ago 10
ARTICLE AD BOX

The documentation says:

Statically Served

It is possible to manually download the files from https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm/dist/.

import * as duckdb from '@duckdb/duckdb-wasm'; const MANUAL_BUNDLES: duckdb.DuckDBBundles = { mvp: { mainModule: 'change/me/../duckdb-mvp.wasm', mainWorker: 'change/me/../duckdb-browser-mvp.worker.js', }, eh: { mainModule: 'change/m/../duckdb-eh.wasm', mainWorker: 'change/m/../duckdb-browser-eh.worker.js', }, }; // Select a bundle based on browser checks const bundle = await duckdb.selectBundle(MANUAL_BUNDLES); // Instantiate the asynchronous version of DuckDB-Wasm const worker = new Worker(bundle.mainWorker!); const logger = new duckdb.ConsoleLogger(); const db = new duckdb.AsyncDuckDB(logger, worker); await db.instantiate(bundle.mainModule, bundle.pthreadWorker);

But the problem is, the "main" file, called in the dist AND in the package duckdb-browser.mjs contains imports to a nodeJS package - import * as u from "apache-arrow"

This obviously will not work in browser. There is no mention of this in the documentation. I can hack around it - for now - but this does not conform to my idea of a "package that runs in browser".

Read Entire Article