Skip to content

Using PGlite or DuckDB-Wasm in the main process breaks building the main target #4149

@noncom

Description

@noncom

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • I have searched the issue tracker for a bug that matches the one I want to file, without success.

Forge version

7.11.1

Electron version

40.6.1

Operating system

Windows 10

Last known working Forge version

No response

Expected behavior

Requiring and using PGlite or DuckDB-Wasm in the main process of Electron should not hang on Building src/main.ts target forever.

Using PGlite or DuckDB-Wasm databases in the main process should be possible.

Actual behavior

The Building src/main.ts target never ends:

✔ Checking your system
✔ Locating application
✔ Loading configuration
✔ Preparing native dependencies [1s]
✔ Running generateAssets hook
❯ Running preStart hook
❯ [plugin-vite] Preparing Vite bundles
✔ Launched Vite dev servers for renderer process code [0.1s]
✔ Target main_window
› ➜ Local: http://localhost:5173/
➜ Network: use --host to expose
❯ Built main process and preload bundles
⠇ Building src/main.ts target
✔ Building src/preload.ts target

Steps to reproduce

Create a fresh Electron Forge project with

npx create-electron-app@latest my-app --template=vite-typescript

Make the following changes in project configs to allow for top-level await:

// In package.json
"type": "module"
// In tsconfig.json
"compilerOptions": {
    "target": "esnext",
    "module": "esnext",
...
}

Install PGlite:

npm install @electric-sql/pglite

Add the following code from PGlite quickstart:

//In main.ts

import { PGlite } from '@electric-sql/pglite'
const db = new PGlite()

await db.exec(`
  CREATE TABLE IF NOT EXISTS todo (
    id SERIAL PRIMARY KEY,
    task TEXT,
    done BOOLEAN DEFAULT false
  );
  INSERT INTO todo (task, done) VALUES ('Install PGlite from NPM', true);
  INSERT INTO todo (task, done) VALUES ('Load PGlite', true);
  INSERT INTO todo (task, done) VALUES ('Create a table', true);
  INSERT INTO todo (task, done) VALUES ('Insert some data', true);
  INSERT INTO todo (task) VALUES ('Update a task');
`)

const ret = await db.query(`
  SELECT * from todo WHERE id = 1;
`)
console.log(ret.rows)

Run

npm run start

Witness the process hanging forever on ⠼ Building src/main.ts target.

The same problem can be repeted for DuckDB-Wasm, but they have more ways of configuring the DB in their quickstart, I won't copy them here, but I tried all of them.

Additional information

Debug output:

PS D:\path\project> npm run start

> project@1.0.0 start
> electron-forge start

❯ Checking your system
  electron-forge:check-system checking system, create ~/.skip-forge-system-check to stop doing this +0ms
❯ Checking package manager version
  electron-forge:package-manager Resolved package manager to npm. (Derived from NODE_INSTALLER: undefined, npm_config_user_agent: npm/11.4.1 node/v22.14.0 win32 x64 workspaces/false, lockfile: npm) +0ms
✔ Found npm@11.4.1
✔ Checking your system
❯ Locating application
  electron-forge:project-resolver searching for project in: D:\path\project +0ms
  electron-forge:project-resolver package.json with forge dependency found in D:\path\project\package.json +2ms
✔ Locating application
❯ Loading configuration
  electron-forge:plugin:vite hooking process events +0ms
✔ Loading configuration
❯ Preparing native dependencies
✔ Preparing native dependencies
❯ Running generateAssets hook
✔ Running generateAssets hook
❯ Running preStart hook
❯ [plugin-vite] Preparing Vite bundles
  electron-forge:plugin:vite preStart: removing old content from D:\path\project\.vite +1s
❯ Launching Vite dev servers for renderer process code...
❯ Target main_window
Port 5173 is in use, trying another one...
›   ➜  Local:   http://localhost:5174/  
➜  Network: use --host to expose
✔ Target main_window
✔ Launched Vite dev servers for renderer process code
❯ Building main process and preload bundles...
❯ Building src/main.ts target
❯ Building src/preload.ts target
Generated an empty chunk: "preload".
16:33:26 [@electron-forge/plugin-vite] target built src/preload.ts
  electron-forge:plugin:vite no error in buildEnd and reached closeBundle so build succeeded +519ms
✔ Building src/preload.ts target
node_modules/@electric-sql/pglite/dist/index.js (1:11906070): Use of eval in "node_modules/@electric-sql/pglite/dist/index.js" is strongly discouraged as it poses security risks and may cause issues with minification.
node_modules/@electric-sql/pglite/dist/index.js (1:11906548): Use of eval in "node_modules/@electric-sql/pglite/dist/index.js" is strongly discouraged as it poses security risks and may cause issues with minification.

16:33:28 Module format "cjs" does not support top-level await. Use the "es" or "system" output formats rather.
file: D:/path/project/src/main.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions