SolidJS Vitest "document is not defined" (missing jsdom) in CI
Vitest defaults to a Node environment with no DOM. Solid tests that render components need jsdom (or happy-dom); without it, calls into document throw "document is not defined" in CI.
What this error means
Locally passing tests fail in CI with "ReferenceError: document is not defined" during render(...), because the CI Vitest config did not set a DOM environment.
vitest
FAIL src/App.test.tsx
ReferenceError: document is not defined
at render (@solidjs/testing-library)Common causes
No DOM test environment configured
Vitest runs in node by default; rendering Solid components needs a simulated DOM.
A missing jsdom/happy-dom dependency
The environment is set but the DOM package is not installed on the runner.
How to fix it
Set the jsdom environment
- Install
jsdomand@solidjs/testing-libraryas dev dependencies. - Set
test.environmenttojsdomin the Vitest config. - Keep the Solid conditions so the browser build is tested.
vitest.config.ts
import { defineConfig } from 'vitest/config';
import solid from 'vite-plugin-solid';
export default defineConfig({
plugins: [solid()],
test: { environment: 'jsdom' },
});Install the DOM package in CI
Ensure jsdom is in devDependencies so npm ci provides it on the runner.
Terminal
npm install -D jsdom @solidjs/testing-libraryHow to prevent it
- Set
test.environment: jsdomfor component tests. - Keep
jsdom/happy-domin devDependencies. - Load
vite-plugin-solidin the Vitest config too.
Related guides
SolidJS createSignal reactivity lost (build ok, test fails) in CIFix SolidJS tests that fail in CI while the build passes - reading a createSignal getter outside a reactive s…
SolidStart SSR "window is not defined" in CIFix SolidStart "ReferenceError: window is not defined" in CI - a browser-only API ran during server-side rend…
Qwik build fails when qwikVite plugin is missing in CIFix Qwik "build failed" in CI when qwikVite / qwikCity plugins are missing from vite.config - Qwik JSX and $…