Vite · VITE0020

Do not use Node APIs in browser workers

Flags node API in worker in Vite worker code before it leaks into runtime behavior.
VITE0020vite-doctor/viteworkerserrorNo fix

Run this rule

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

Why it matters

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

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()))
Copyright © 2026