Vite · VITE0022

Use literal patterns in import.meta.glob

Reports import.meta.glob patterns that Vite cannot transform into module imports.
VITE0022vite-doctor/viteimportserrorNo fix
vite/imports/require-static-glob-patternsrc/rule-packs/vite/rules/imports.ts Upstream docs

Run this rule

pnpm vite-doctor . --framework vite --rules vite/imports/require-static-glob-pattern

Why it matters

Vite expands import.meta.glob during development and production builds. Its first argument must contain string literals, an array of string literals, or template literals without interpolation. Variables, concatenation, interpolated templates, and array spreads are unsupported even when their values are constant. Vite 7 rejects them during the transform; Vite 8 can instead omit their matching modules from the generated map.

Write the patterns directly inside import.meta.glob. To choose a module at runtime, use a literal glob to build the module map, then select a key from that map.

Example

Inline constant patterns

Before

const pattern = './pages/*.vue'
const pages = import.meta.glob(pattern)

After

const pages = import.meta.glob('./pages/*.vue')

Select a module after expanding a literal glob

Before

const loadPage = (name: string) => import.meta.glob(`./pages/${name}.vue`)

After

const pages = import.meta.glob('./pages/*.vue')
const loadPage = (name: string) => pages[`./pages/${name}.vue`]?.()
Copyright © 2026