0

I am stuck for several days with duckDB nodeJS binding from NPM. I am simply trying a database creation with:

import * as duckdb from 'duckdb'
   
const db = new duckdb.Database(':memory:');

but this triggers the following error:

const db = new duckdb.Database(':memory:');
           ^

TypeError: duckdb.Database is not a constructor
    at file:///home/juju/workspace/gridtiler/npm/bin/gridtiler.js:64:12
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)
    at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24)
    at async loadESM (node:internal/process/esm_loader:40:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.4.0

while Database class is loaded. The execution does not recognize it as a class, apparently.

Is there something I missed?

A console.log(duckdb) returns:

[Module: null prototype] {
  default: {
    Database: [Function: Database],
    Connection: [Function: Connection],
    Statement: [Function: Statement],
    QueryResult: [Function: QueryResult],
    ERROR: -1,
    OPEN_READONLY: 1,
    OPEN_READWRITE: 0,
    OPEN_CREATE: 0,
    OPEN_FULLMUTEX: 0,
    OPEN_SHAREDCACHE: 0,
    OPEN_PRIVATECACHE: 0
  }
}

which shows that Database class should be available...

1 Answer 1

1

OK... Just replacing import * as duckdb from 'duckdb' with import duckdb from 'duckdb' solved the issue.

Otherwise, duckdb.default.Database should be used instead of duckdb.Database.

Sign up to request clarification or add additional context in comments.

Comments

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.