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.
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.
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.
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.