VITE0027Convert import.meta.url URLs with fileURLToPath
Why it happens
A URL's pathname is not a file system path. It keeps percent-encoding, so a project under a directory with a space resolves to .../My%20App/..., and on Windows it starts with /C:/ instead of a drive letter path. Alias targets, build inputs, and fs reads built from it then point at files that do not exist. Doctor checks vite.config.* and vitest.config.* files and modules that import from vite, vite-plus, or vitest/config. It reports .pathname on new URL(..., import.meta.url), directly or through a const. URLs built from other bases, such as request URLs used for routing, are not reported.
Fix
Wrap the URL with fileURLToPath from node:url: fileURLToPath(new URL('./src/file.ts', import.meta.url)).
Example
Convert file URLs with fileURLToPath
Before
import { defineConfig } from 'vitest/config'
export default defineConfig({
resolve: {
alias: {
'#registry': new URL('./src/runtime/empty-registry.ts', import.meta.url).pathname,
},
},
})
After
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vitest/config'
export default defineConfig({
resolve: {
alias: {
'#registry': fileURLToPath(new URL('./src/runtime/empty-registry.ts', import.meta.url)),
},
},
})
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 --rules vite/config/no-url-pathname-as-fs-path