2

I'm working on a Parcel frontend project using DuckDB, and it runs well in the Production environment. However, in my local machine the browser displays this error.

And as I've just mentioned, this issue is not happening in the production environment. The node version is 22.18.0

This is the entire code in the src/duckdb.js file which I think is causing the issue:

/* global Worker */

import * as duckdb from "@duckdb/duckdb-wasm";
import duckdb_wasm from "url:@duckdb/duckdb-wasm/dist/duckdb-mvp.wasm";
import mvp_worker from "url:@duckdb/duckdb-wasm/dist/duckdb-browser-mvp.worker.js";
import duckdb_wasm_eh from "url:@duckdb/duckdb-wasm/dist/duckdb-eh.wasm";
import eh_worker from "url:@duckdb/duckdb-wasm/dist/duckdb-browser-eh.worker.js";

const MANUAL_BUNDLES = {
  mvp: {
    mainModule: duckdb_wasm,
    mainWorker: mvp_worker,
  },
  eh: {
    mainModule: duckdb_wasm_eh,
    mainWorker: eh_worker,
  },
};
let _db,
  _initialized = false;

async function init() {
  if (_initialized) return;
  _initialized = true;
  let db;
  try {
    // Select a bundle based on browser checks
    const bundle = await duckdb.selectBundle(MANUAL_BUNDLES);
    // Instantiate the asynchronus version of DuckDB-wasm
    const worker = new Worker(bundle.mainWorker);
    const logger = new duckdb.ConsoleLogger();
    db = new duckdb.AsyncDuckDB(logger, worker);
    await db.instantiate(bundle.mainModule, bundle.pthreadWorker);

    const conn = await db.connect();
    await conn.query("SELECT 1;");
    await conn.close();
  } catch (e) {
    console.log("Error instantiating duckdb");
    console.error("Error instantiating duckdb", e);
    return;
  }
  _db = db;
}

const getDB = async () => {
  await init();
  return _db;
};
export default { getDB, ...duckdb };

I've tried asking the AI, but it seems to be even more confused than me.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.