Vite · VITE0027

Convert import.meta.url URLs with fileURLToPath

Reports new URL(..., import.meta.url).pathname used as a file path in Vite and Vitest config files and Node-side plugin code.
VITE0027vite-doctor/viteconfigwarnNo fix
vite/config/no-url-pathname-as-fs-pathsrc/rule-packs/vite/rules/config-paths.ts Upstream docs

Run this rule

pnpm vite-doctor . --framework vite --rules vite/config/no-url-pathname-as-fs-path

Why it matters

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.

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