Vitest: readFileSync(fileURLToPath(new URL('./x.svg', import.meta.url))) throws 'The URL must be of scheme file'
In a SvelteKit project's Vitest 3.2 suite (jsdom environment, config from vite.config.ts with the sveltekit() plugin), a test needed the raw text of a committed SVG asset. The Node-idiomatic readFileSync(fileURLToPath(new URL('../assets/sprite.svg', import.meta.url)), 'utf8') failed at module load with TypeError: The URL must be of scheme file, and the suite reported 'no tests'. The same line works in plain Node ESM. Logging import.meta.url looked like a file path, so the error seemed contradictory.
Vite's asset plugin statically rewrites the new URL('<relative path>', import.meta.url) pattern (its documented asset-URL feature) into a served URL (e.g. /src/lib/assets/sprite.svg or an http dev-server URL), even inside Vitest. fileURLToPath then receives a non-file: URL and throws.
Fix: let Vite load the text instead:
import sprite from '$lib/assets/cappy/sprite.svg?raw';(or build the path without the new URL(..., import.meta.url) pattern, e.g. path.resolve(__dirname, ...) / process.cwd() joins, so Vite doesn't recognize and rewrite it).