Skip to content

DuckDB-wasm browser bundle fails in Electron renderer when nodeIntegrationInWorker is true #2074

@superduke

Description

@superduke

What happens?

When using the @duckdb/duckdb-wasm browser bundle in an Electron renderer process, everything works as expected if nodeIntegrationInWorker is set to false. However, when I set nodeIntegrationInWorker: true in the BrowserWindow options, I encounter the following error:

Uncaught TypeError: Cannot read properties of undefined (reading 'from')
    at b (sha256.js:87:16)
    at h (sha256.js:67:16)
    at sha256.js:509:17
    at sha256.js:526:1
    at duckdb-browser-eh.worker.js:1:634
    at s3_helper.ts:2:22
    at duckdb-browser-eh.worker.ts:33:16
    at f5b87803-5a4a-42c1-b1fe-ab1771d8e224:1:1

This error occurs when calling Buffer.from inside the worker. It appears that enabling nodeIntegrationInWorker changes the worker’s environment so that Buffer is not correctly defined, which causes the browser bundle to fail.

To Reproduce

See https://github.com/MasterOdin/electron-duckdb-wasm. Changing this line:

https://github.com/MasterOdin/electron-duckdb-wasm/blob/1cd5f871eac0fa1a24d9807b0f8a9ab4eac3c78f/main.js#L14

where if it's true then will see the above error(different from the error described in the repo) , and if it's false then the query runs and I get my result.

Great thanks to MasterOdin for his repo!

Browser/Environment:

Electron 26, 37

Device:

Macbook Pro

DuckDB-Wasm Version:

1.29.0

DuckDB-Wasm Deployment:

JS Delivr

Full Name:

Duke Zhang

Affiliation:

IdeaLeap

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions