-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Describe the bug
I’m occasionally seeing Vitest report unhandled promise rejections during a test run with the error:
Error: [vitest-worker]: Closing rpc while "fetch" was pending
This happens intermittently both locally and in CI, sometimes without any apparent change in the code or environment. The test run still reports all test files and tests as passing, but the run ends with “Vitest caught N unhandled errors” and exits with errors.
From what I can tell, the error is raised while Vitest/Vite is importing modules during the test execution (module runner), and the stack trace points to a component barrel export file, but the error message suggests a worker RPC shutdown while a “fetch” is still pending.
Expected behavior
- No unhandled rejections during the run.
- If a worker is closing while something is pending, I’d expect a clearer actionable message (or a deterministic failure pointing at the underlying cause).
- Test runs that pass should not randomly end with “unhandled errors” without a clear failing file/root cause.
Actual behavior
- Tests report as passing, but Vitest prints Unhandled Errors / Unhandled Rejection and finishes with Errors > 0.
- The stack trace often references module imports (Vite module runner) rather than a specific failing assertion.
- Occurs sporadically (hard to reproduce deterministically).
Reproduction
Reproduction
Unfortunately I don’t have a minimal reproduction yet because it’s intermittent:
- Run the full test suite multiple times (local or CI).
- Occasionally the run ends with unhandled errors even though tests all pass.
If there are recommended flags/config to increase determinism or get more diagnostics (e.g. verbose worker/module runner logs), I can try them and report back.
Environment
- Vitest:
<vitest version> - Vite:
<vite version> - Node:
<node version> - OS:
<macOS/Linux + version> - Runner:
<CI provider + runner type>(when applicable) - Workspace: monorepo with component library imports (Vue SFCs), using barrel exports.
Logs (anonymized)
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Vitest caught 3 unhandled errors during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: [vitest-worker]: Closing rpc while "fetch" was pending
❯ reviveInvokeError node_modules/vitest/node_modules/vite/dist/node/module-runner.js:475:14
❯ Object.invoke node_modules/vitest/node_modules/vite/dist/node/module-runner.js:491:33
❯ processTicksAndRejections node:internal/process/task_queues:105:5
❯ VitestModuleRunner.getModuleInformation node_modules/vitest/node_modules/vite/dist/node/module-runner.js:1086:7
❯ request node_modules/vitest/node_modules/vite/dist/node/module-runner.js:1103:83
❯ <repo>/libs/<ui-lib>/src/components/<Button>/index.ts:1:1
1| export { default as RemoveActionButton } from "./RemoveActionButton.vue";
| ^
2| export { default as BaseButton } from "./BaseButton.vue";
3| export { default as IconButton } from "./IconButton.vue";
❯ VitestModuleEvaluator._runInlinedModule node_modules/vitest/dist/module-evaluator.js:197:4
❯ VitestModuleRunner.directRequest node_modules/vitest/node_modules/vite/dist/node/module-runner.js:1146:59
❯ VitestModuleRunner.cachedRequest node_modules/vitest/node_modules/vite/dist/node/module-runner.js:1053:73
❯ <repo>/libs/<ui-lib>/src/index.ts:1:1
This error originated in "<repo>/libs/<ui-lib>/src/components/<Form>/__tests__/FormField.spec.ts" test file.
It doesn't mean the error was thrown inside the file itself, but while it was running.
(repeats 3 times)
Test Files 109 passed (109)
Tests 1809 passed (1809)
Errors 3 errors
Start at <timestamp>
Duration <duration> (transform <..>, import <..>, tests <..>, environment <..>)Notes / hints
- The error mentions
"fetch"being pending, but I’m not explicitly callingfetch()in this test file. - It may be related to module loading/transform/import in the worker, or some plugin / environment behavior (Vue SFC transform / JSDOM / happy-dom, etc.).
- Because tests pass, this looks like an infrastructure/runner lifecycle issue rather than a typical assertion failure.
System Info
System:
OS: macOS 26.1
CPU: (10) arm64 Apple M1 Pro
Memory: 207.23 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.11.0 - /Users/corentin/.nvm/versions/node/v24.11.0/bin/node
Yarn: 4.3.1 - /usr/local/bin/yarn
npm: 11.6.1 - /Users/corentin/.nvm/versions/node/v24.11.0/bin/npm
bun: 1.2.21 - /Users/corentin/.bun/bin/bun
Watchman: 2025.05.26.00 - /opt/homebrew/bin/watchman
Browsers:
Brave Browser: 132.1.74.51
Chrome: 143.0.7499.193
Edge: 143.0.3650.139
Firefox: 146.0.1
Safari: 26.1
npmPackages:
@vitejs/plugin-vue: ^6.0.3 => 6.0.3
@vitest/coverage-v8: ^1.6.1 => 1.6.1
@vitest/ui: ^1.6.1 => 1.6.1
vite: ^7.1.11 => 7.3.0
vitest: ^4.0.16 => 4.0.16Used Package Manager
yarn
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.