Vite · Workers

VITE0020Do not use Node APIs in browser workers

Flags node API in worker in Vite worker code before it leaks into runtime behavior.

Why it happens

Vite configuration runs in both dev and build pipelines. Narrow, explicit settings reduce surprises across SSR, workers, and local file access.

Fix

Remove node API in worker, or move it to the Vite runtime/API that owns that behavior.

Example

Avoid Node APIs in workers

Before

import { readFileSync } from 'node:fs'

self.postMessage(readFileSync('data.txt', 'utf8'))

After

self.postMessage(await fetch('/data.txt').then(r => r.text()))

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --framework vite --extends auto,vite/strict --rules vite/worker/no-node-api-in-worker
Copyright © 2026