Skip to content

Building ?worker works in dev but bundling with Terser errors #9566

@milomg

Description

@milomg

Describe the bug

When using Terser and Workers on non-trivial dependencies, vite seems to exhibit a concurrency bug which causes terser to error and forces the bundle to stop. However, this bug is particularly confusing for developers because it doesn't mention terser at all! Instead, it says

Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:
(vite:worker) transform "vitebug/node_modules/.pnpm/monaco-editor@0.34.0/node_modules/monaco-editor/esm/vs/language/typescript/ts.worker.js?worker"

Ideally whatever error terser is causing should be correctly logged (and terser shouldn't error on this worker bundle).

I've tried to figure out what error is stopping the build but it seems like importing terser just immediately halts the worker with no errors logged

I also tested this bug on stackblitz and it seems that it is missing the on("beforeExit") nodejs feature so doesn't log anything and instead silently outputs nothing: https://stackblitz.com/edit/vite-workers-bug

Reproduction

https://github.com/modderme123/vitebug/

System Info

System:
    OS: macOS 12.5
    CPU: (8) x64 Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz
    Memory: 17.69 MB / 16.00 GB
    Shell: 3.5.1 - /usr/local/bin/fish
  Binaries:
    Node: 18.7.0 - /usr/local/bin/node
    npm: 8.16.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 103.0.5060.134
    Safari: 15.6
  npmPackages:
    vite: ^3.0.4 => 3.0.4

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: web workersp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions