Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
7 tasks done
modderme123 opened this issue Aug 7, 2022 · 5 comments
Closed
7 tasks done

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

modderme123 opened this issue Aug 7, 2022 · 5 comments
Labels
feat: web workers p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@modderme123
Copy link
Contributor

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

@modderme123
Copy link
Contributor Author

modderme123 commented Aug 7, 2022

Related: #1927, #2689

In that case the asset plugin finish was being called twice and wiping the outputted assets (sort of like a use after free).

@beginnerJq

This comment was marked as duplicate.

@pastelmind
Copy link
Contributor

I had a similar issue when using the following import syntax for web workers.

import MyWorker from './path/to/my-worker?worker'
const worker = new MyWorker()

This caused the build to fail in GitHub Actions with a similar error message as the one described by @modderme123.

We worked around the issue by using the ?url syntax:

import MyWorkerUrl from './path/to/my-worker?url'
const worker = new Worker(MyWorkerUrl, { type: 'module' })

@pastelmind
Copy link
Contributor

...and I'm running into a different bug. In the generated bundle, the web worker is encoded as a data URL with the wrong MIME type: data:video/mp2t;base64,aW1wb3.... This seems to be related to #2642 and #4167--

@sapphi-red
Copy link
Member

Closing as I confirmed this is fixed from 4.0.0-beta.1. I guess #11218 fixed this.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: web workers p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

4 participants