Skip to content

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

Open

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

Activity

  1. added theissue type on Feb 26, 2026
  2. noncom commented on Feb 26, 2026

    @noncom
    Author

    I just realized that there's probably two problems at once. I'm new to this ecosystem, so I got confused a bit.

    The problem that Electron debug prints out, Module format "cjs" does not support top-level await. Use the "es" or "system" output formats rather in the log above seems to be #3943. I haven't seen this message prior to enabling debug which was suggested when I was already creating the ticket.

    But also there's another problem covered by it. If I remove all the added code, and only keep this:

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

    then it does start with debug enabled, but there are different errors in the log, see at the bottom:

    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:44:48 [@electron-forge/plugin-vite] target built src/preload.ts
      electron-forge:plugin:vite no error in buildEnd and reached closeBundle so build succeeded +505ms
    ✔ 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:44:50 [@electron-forge/plugin-vite] target built src/main.ts
      electron-forge:plugin:vite no error in buildEnd and reached closeBundle so build succeeded +2s
    ✔ Building src/main.ts target
    ✔ Built main process and preload bundles
    ✔ [plugin-vite] Preparing Vite bundles
    ✔ Running preStart hook
    ✔ Launched Electron app. Type rs in terminal to restart main process.
      electron-forge:start Electron binary path: D:\path\project\node_modules\electron\dist\electron.exe +0ms
      electron-forge:plugin:vite hooking electron process exit +15ms
    
    
    (node:42620) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file
        at splitPath (node:electron/js2c/node_init:2:1032)
        at t.promises.readFile (node:electron/js2c/node_init:2:10800)
        at Er (D:\path\project\.vite\build\main2.cjs:904:30237257)
        at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
    (Use `electron --trace-warnings ...` to show where the warning was created)
    (node:42620) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on 
    unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
    (node:42620) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file
        at splitPath (node:electron/js2c/node_init:2:1032)
        at t.promises.readFile (node:electron/js2c/node_init:2:10800)
        at Er (D:\path\project\.vite\build\main2.cjs:904:30237257)
        at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
    (node:42620) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on 
    unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
    
  3. noncom commented on Mar 8, 2026

    @noncom
    Author

    For anyone interested, there's a solution now, kindly provided by @UmbrellaCrow612. The PR fully explains it and fixes the problem.

    Long story short, using Vite on the backend side of Electron complicates things more than it does any good, it seems.

    I don't know if this can be considered solved and closed, as yes there's a way to use PGlite and Wasm in the backend, but the electron-vite template is still broken in the sense that it doesn't allow doing that. All my prior searches for any issues in using Wasm with Vite revealed a lot of various cases, but in different circumstanes, and none of the solutions worked in this case. So I would say that from my observation it is simply impossible to use the electron-vite template for apps with Wasm in the backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions