import-meta-glob-literal
Require import.meta.glob() to receive static string literals or arrays of static string literals.
Rule catalog ID: R002
Targeted pattern scopeโ
- browser-bound Vite source
- route discovery and content-loading utilities
- code that uses
import.meta.glob(...)
What this rule reportsโ
This rule reports import.meta.glob() calls whose first argument is not:
- a string literal
- a template literal without expressions
- an array made only from those literal forms
Why this rule existsโ
Vite expands import.meta.glob() statically.
If the pattern is dynamic, Vite cannot precompute the module set correctly.
โ Incorrectโ
const pagesPattern = "./pages/**/*.md";
const pages = import.meta.glob(pagesPattern);
const section = "blog";
const modules = import.meta.glob(`./content/${section}/*.md`);
โ Correctโ
const pages = import.meta.glob("./pages/**/*.md");
const modules = import.meta.glob([
"./content/blog/*.md",
"./content/docs/*.md",
]);
Behavior and migration notesโ
- move dynamic selection logic after the glob import instead of inside the glob pattern
- keep the glob itself static and filter the returned module map in normal JavaScript
ESLint flat config exampleโ
import vite from "@typpi/eslint-plugin-vite";
export default [vite.configs.client];
When not to use itโ
Disable this rule only if your codebase never uses import.meta.glob().