Vite · Plugins

VITE0028Keep # out of virtual module ids the browser loads

Reports when a registered Vite resolveId hook resolves a browser import to a virtual module id containing #.

Why it happens

Vite dev serves virtual modules at /@id/ followed by the resolved id, with \0 written as x00. Vite does not encode #, so a browser given /@id/x00#app/config requests only /@id/x00, and the import fails. Doctor reads supported Vite configs without executing them and checks registered hooks in resolution order under client conditions. It reports the return value or module-level const only when it can determine which resolver handles the import. Dynamic configs, unknown plugin registrations, or unsupported filters and branches can prevent a result. Browser entry evidence includes Vue SFCs, .client modules, modules importing Vue runtime APIs, and HTML module scripts and their local dependencies. Type-only imports and external URLs do not trigger this rule.

Fix

Resolve the specifier to an id without #, such as \0virtual:app/config, and update the load hook and its filter. The import specifier users write can keep its #.

Example

Keep # in the specifier, not in the resolved id

Before

const PUBLIC_ID = '#app/config'
const RESOLVED_PUBLIC_ID = `\0${PUBLIC_ID}`

export function config(): Plugin {
  return {
    name: 'config',
    resolveId(id) {
      if (id === PUBLIC_ID) return RESOLVED_PUBLIC_ID
    },
    load(id) {
      if (id === RESOLVED_PUBLIC_ID) return 'export default {}'
    },
  }
}

After

const PUBLIC_ID = '#app/config'
const RESOLVED_PUBLIC_ID = '\0virtual:app/config'

export function config(): Plugin {
  return {
    name: 'config',
    resolveId(id) {
      if (id === PUBLIC_ID) return RESOLVED_PUBLIC_ID
    },
    load(id) {
      if (id === RESOLVED_PUBLIC_ID) return 'export default {}'
    },
  }
}

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/plugin/no-fragment-in-virtual-id
Copyright © 2026