question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Building `?worker` works in dev but bundling with Terser errors

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
modderme123commented, Aug 7, 2022

Related: https://github.com/vitejs/vite/issues/1927, https://github.com/vitejs/vite/pull/2689

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

0reactions
sapphi-redcommented, Dec 7, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging Story: Build failed, error from Terser - Tan Li Hau
It all started with an error message during the build: 'ERROR in bundle.xxx.js from Terser'.
Read more >
how solve error jest-worker at run build? - Stack Overflow
It worked when I downgraded terser-webpack-plugin to 2.3.6. ... using a version earlier than 10.13, or downgrade your terser-webpack-plugin.
Read more >
How I solved and debugged my Webpack issue through trial ...
When webpack bundles your source code, it can become difficult to track down errors and warnings to their original location.
Read more >
Build Performance - webpack
This guide contains some useful tips for improving build/compilation performance. General. The following best practices should help, whether you're running ...
Read more >
terser-webpack-plugin | Yarn - Package Manager
If you use Circle CI or any other environment that doesn't provide real available count of CPUs then you need to setup explicitly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found