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

Worker and build only error: Unexpected early exit. This happens when Promises returned by plugins cannot resolve #13367

Closed
7 tasks done
vegarringdal opened this issue May 29, 2023 · 14 comments · Fixed by #14685
Labels
feat: web workers p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@vegarringdal
Copy link

Describe the bug

I have issues with build when I have worker inside worker when using sqllite when I have workers in workers
Works fine in dev, but not in build
Though it first was a sqllite/wasm issue and something I was missing. but found out their stackblitz worked fine even on build
So stripped it down to just vite as dependency

Asked here before I created the issue, just incase I was doing something wrong
#13357

@sapphi-red FYI

Reproduction

https://stackblitz.com/edit/vitejs-vite-zafzfp

Steps to reproduce

download and try and run npm run build

It runs fine in dev mode (see image 1), but if you download it and try and run npm run build you get (see image2)

Image 1
image

Image 2
image

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
    Memory: 16.01 GB / 31.95 GB
  Binaries:
    Node: 18.12.1 - C:\Program Files\nodejs\node.EXE
    npm: 8.12.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.1702.0), Chromium (113.0.1774.57)
    Internet Explorer: 11.0.22621.1

Used Package Manager

npm

Logs

Click to expand!
> [email protected] build
> vite build --debug

  vite:config bundled config file loaded in 56.13ms +0ms
  vite:config using resolved config: {
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     headers: {
  vite:config       'Cross-Origin-Opener-Policy': 'same-origin',
  vite:config       'Cross-Origin-Embedder-Policy': 'require-corp'
  vite:config     },
  vite:config     sourcemapIgnoreList: [Function: isInNodeModules],
  vite:config     middlewareMode: false,
  vite:config     fs: { strict: true, allow: [Array], deny: [Array] }
  vite:config   },
  vite:config   optimizeDeps: {
  vite:config     disabled: 'build',
  vite:config     exclude: [ '@sqlite.org/sqlite-wasm' ],
  vite:config     esbuildOptions: { preserveSymlinks: false }
  vite:config   },
  vite:config   build: {
  vite:config     target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
  vite:config     cssTarget: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     sourcemap: false,
  vite:config     rollupOptions: {},
  vite:config     minify: 'esbuild',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     copyPublicDir: true,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     ssrEmitAssets: false,
  vite:config     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] },
  vite:config     modulePreload: { polyfill: true },
  vite:config     cssMinify: true
  vite:config   },
  vite:config   configFile: 'D:/github/s/vite.config.js',
  vite:config   configFileDependencies: [ 'D:/github/s/vite.config.js' ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     optimizeDeps: { force: undefined },
  vite:config     build: {}
  vite:config   },
  vite:config   root: 'D:/github/s',
  vite:config   base: '/',
  vite:config   rawBase: '/',
  vite:config   resolve: {
  vite:config     mainFields: [ 'module', 'jsnext:main', 'jsnext' ],
  vite:config     browserField: true,
  vite:config     conditions: [],
  vite:config     extensions: [
  vite:config       '.mjs',  '.js',
  vite:config       '.mts',  '.ts',
  vite:config       '.jsx',  '.tsx',
  vite:config       '.json'
  vite:config     ],
  vite:config     dedupe: [],
  vite:config     preserveSymlinks: false,
  vite:config     alias: [ [Object], [Object] ]
  vite:config   },
  vite:config   publicDir: 'D:\\github\\s\\public',
  vite:config   cacheDir: 'D:/github/s/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   ssr: {
  vite:config     format: 'esm',
  vite:config     target: 'node',
  vite:config     optimizeDeps: { disabled: true, esbuildOptions: [Object] }
  vite:config   },
  vite:config   isWorker: false,
  vite:config   mainConfig: null,
  vite:config   isProduction: true,
  vite:config   plugins: [
  vite:config     'vite:build-metadata',
  vite:config     'vite:watch-package-data',
  vite:config     'vite:pre-alias',
  vite:config     'alias',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html-inline-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm-helper',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite:wasm-fallback',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:asset-import-meta-url',
  vite:config     'vite:force-systemjs-wrap-complete',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'vite:dynamic-import-vars',
  vite:config     'vite:import-glob',
  vite:config     'vite:build-import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:reporter',
  vite:config     'vite:load-fallback'
  vite:config   ],
  vite:config   esbuild: { jsxDev: false },
  vite:config   preview: {
  vite:config     port: undefined,
  vite:config     strictPort: undefined,
  vite:config     host: undefined,
  vite:config     https: undefined,
  vite:config     open: undefined,
  vite:config     proxy: undefined,
  vite:config     cors: undefined,
  vite:config     headers: {
  vite:config       'Cross-Origin-Opener-Policy': 'same-origin',
  vite:config       'Cross-Origin-Embedder-Policy': 'require-corp'
  vite:config     }
  vite:config   },
  vite:config   envDir: 'D:/github/s',
  vite:config   env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen],
  vite:config     hasErrorLogged: [Function: hasErrorLogged]
  vite:config   },
  vite:config   packageCache: Map(1) {
  vite:config     'fnpd_D:/github/s' => {
  vite:config       'vite:dynamic-import-vars',
  vite:config       'vite:import-glob',
  vite:config       'vite:build-import-analysis',
  vite:config       'vite:esbuild-transpile',
  vite:config       'vite:terser',
  vite:config       'vite:load-fallback'
  vite:config     ],
  vite:config     rollupOptions: {},
  vite:config     getSortedPlugins: [Function: getSortedPlugins],
  vite:config     getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config   },
  vite:config   appType: 'spa',
  vite:config   experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
  vite:config   getSortedPlugins: [Function: getSortedPlugins],
  vite:config   getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config } +17ms
vite v4.3.5 building for production...
  vite:esbuild 43.32ms tsconfck init D:/github/s +0ms
transforming (1) index.htmlUnexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:
(vite:worker-import-meta-url) transform "D:/github/s/script.js"
error during build:
Error: Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:
(vite:worker-import-meta-url) transform "D:/github/s/script.js"
    at EventEmitter.handleEmptyEventLoop (file:///D:/github/s/node_modules/rollup/dist/es/shared/node-entry.js:24909:20)
    at Object.onceWrapper (node:events:627:28)
    at EventEmitter.emit (node:events:525:35)
    at process.<anonymous> (file:///D:/github/s/node_modules/rollup/dist/es/shared/node-entry.js:24903:55)
    at process.emit (node:events:513:28)
    

Validations

@stackblitz
Copy link

stackblitz bot commented May 29, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) feat: web workers labels May 29, 2023
@faga295 faga295 mentioned this issue May 31, 2023
9 tasks
@onetrickwolf
Copy link

Any known workaround to this in the meantime?

@afloury
Copy link

afloury commented Jun 28, 2023

I had the same error message on my project :

yarn vite build --mode dev
yarn run v1.22.19
$ vite build --mode dev
vite v4.3.9 building for dev...
transforming (419) 
Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:
(vite:worker-import-meta-url) transform "/Users/project/src/utils/worker-connector.ts"
error during build:
Error: Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:
(vite:worker-import-meta-url) transform "/Users/project/src/utils/worker-connector.ts"
    at process.handleBeforeExit (file:///Users/project/node_modules/rollup/dist/es/shared/node-entry.js:25014:28)
    at Object.onceWrapper (node:events:628:26)
    at process.emit (node:events:513:28)
error Command failed with exit code 1.

My issue was a bit different than your but I wanted to share it in case someone is facing the same problem as it took me some time to fixed it.

So I got this because I was importing some functions from my utils folder, and in my utils folder I have a /utils/index.ts file where I put the export of my functions from other utils files like this :

export { encryptText, decryptText } from "./crypto-web"

And I was importing it in my worker/worker.ts file like this :

import { decryptText, encryptText } from "@/utils"

This was working fine in dev, but got the error in build.

To fix it I had to change the import to reference the full file and make sure there is no interdependence (or same import style) inside the file I'm importing (only for import and files related to the worker), like this :

import { decryptText, encryptText } from "../utils/crypto-web"

Fixed my build.

Hope this will help someone.

@patratel
Copy link

patratel commented Jul 2, 2023

Hey,

I've encountered the same issue, although I'm not spawning workers inside workers. I'm using one worker which imports the @jsquash/avif library and encodes an image. It works fine in dev mode but when trying to build with vite I get the same error as the people above. Is a fix in the working?

@voxelstack
Copy link

This also happens when a worker imports wasm_bindgen code that uses wasm_bindgen_rayon.

@AntonOfTheWoods
Copy link

AntonOfTheWoods commented Jul 25, 2023

Is this vite or rollup? It also happens when importing wa-sqlite but, at least for me, only when I am trying to build a (crx)[https://crxjs.dev/vite-plugin] background worker. When I build for the website, it's fine.

UPDATE: this went away when I moved the (buggy) code that was creating a worker and being included in the code built for the background worker (using vite-plugin-pwa).

@ghost
Copy link

ghost commented Aug 2, 2023

Not spawning worker in worker but same error. Dev mode works fine but build fails.
How is it possible the two modes to differ this much?
Is there any solution besides switching to something else??

@Vanilagy
Copy link

Vanilagy commented Aug 13, 2023

Can also confirm this errors for wasm_bindgen_rayon, as it starts its own set of (nested) Workers. I know nested Workers sounds somewhat niche, and it is marked as a minor bug, but it is a valid use case and Vite erroring for it simply limits me in the stuff I can build. Hope this gets addressed soon.

@onetrickwolf
Copy link

Yeah my issue is with wasm_bindgen_rayon too I tried quite a bit to get it working but ultimately had to use webpack for builds while using vite for the dev server which is not ideal. The webpack dev server is extremely slow (~20 seconds vs <1 second for vite) so it is still worth it for me to use vite for dev but wish I could find a work around for the vite build.

@jamsinclair
Copy link
Contributor

jamsinclair commented Aug 15, 2023

Linking a few resources to help give this issue context.

This is breaking due to the serialisation of Worker rollup builds. There's an unresolvable promise because two rollup builds rely on each other to resolve.

userquin added a commit to userquin/vite that referenced this issue Oct 13, 2023
When we have multiple workers, the config cannot be used as web map key since the config can mutate.

Since we're not in a multi-thread environment we can use a fixed key to store the promise of the current worker build.

You can use the reproduction provided in vitejs#13367 , when building the third worker, there is a pending promise since the config changes and there is no way to delete it and then the error.
@userquin userquin mentioned this issue Oct 13, 2023
9 tasks
@brendon
Copy link

brendon commented Oct 19, 2023

Just wondering what the current steps are to fix or patch around this issue? The error message doesn't offer any help as to where things are fouling up for me. I even tried commenting everything out in my entry point files to no avail.

@brendon
Copy link

brendon commented Oct 19, 2023

Just wondering what the current steps are to fix or patch around this issue? The error message doesn't offer any help as to where things are fouling up for me. I even tried commenting everything out in my entry point files to no avail.

For me, downgrading to Vite 4.2.x got me back on the road again. I'd still love to hear about how one would go about figuring out the particular culprit in these scenarios. It seems related to plugins?

@Vanilagy
Copy link

Lol, is this fixed?

@patak-dev
Copy link
Member

Hey @Vanilagy, #14685 has been released in [email protected]. Did it work for your use case?

@github-actions github-actions bot locked and limited conversation to collaborators Nov 3, 2023
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