vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
67.18k stars 6.04k forks source link

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

Closed vegarringdal closed 11 months ago

vegarringdal commented 1 year ago

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 https://github.com/vitejs/vite/discussions/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! ```shell > vite-project@0.0.0 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. (file:///D:/github/s/node_modules/rollup/dist/es/shared/node-entry.js:24903:55) at process.emit (node:events:513:28) ```

Validations

stackblitz[bot] commented 1 year ago

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

onetrickwolf commented 1 year ago

Any known workaround to this in the meantime?

afloury commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

AntonOfTheWoods commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.

brendon commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

Lol, is this fixed?

patak-dev commented 11 months ago

Hey @Vanilagy, #14685 has been released in vite@5.0.0-beta.11. Did it work for your use case?