{"record":{"id":"05baa4b0e3052cca","repo":"vitejs/vite","slug":"module-runner-import-meta-glob-is-statically-r","errorCode":null,"errorMessage":"[module runner] \"import.meta.glob\" is statically replaced during file transformation. Make sure to reference it by the full name.","messagePattern":"\\[module runner\\] \"import\\.meta\\.glob\" is statically replaced during file transformation\\. Make sure to reference it by the full name\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/module-runner/createImportMeta.ts","lineNumber":30,"sourceCode":"})\n\nexport function createDefaultImportMeta(\n  modulePath: string,\n): ModuleRunnerImportMeta {\n  const href = posixPathToFileHref(modulePath)\n  const filename = modulePath\n  const dirname = posixDirname(modulePath)\n  return {\n    filename: isWindows ? toWindowsPath(filename) : filename,\n    dirname: isWindows ? toWindowsPath(dirname) : dirname,\n    url: href,\n    env: envProxy,\n    resolve(_id: string, _parent?: string) {\n      throw new Error('[module runner] \"import.meta.resolve\" is not supported.')\n    },\n    // should be replaced during transformation\n    glob() {\n      throw new Error(\n        `[module runner] \"import.meta.glob\" is statically replaced during ` +\n          `file transformation. Make sure to reference it by the full name.`,\n      )\n    },\n  }\n}\n\n/**\n * Create import.meta object for Node.js.\n */\nexport function createNodeImportMeta(\n  modulePath: string,\n): ModuleRunnerImportMeta {\n  const defaultMeta = createDefaultImportMeta(modulePath)\n  const href = defaultMeta.url\n\n  const importMetaResolver = createImportMetaResolver()\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/vitejs/vite/blob/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/module-runner/createImportMeta.ts#L12-L48","documentation":"`import.meta.glob` is not a real runtime function - Vite statically transforms it into an import map during file transformation. If the call survives to the module runner (i.e. the proxy/placeholder `glob()` throws), it means the transform did not replace it, almost always because the code references it indirectly (via a renamed alias, a variable, `window['import.meta.glob']`-style access, or code that the Vite plugin pipeline never processed).","triggerScenarios":"Aliasing `import.meta.glob` to a short variable (`const g = import.meta.glob; g(...)`), passing it as a callback, string-looking it up, or executing code outside Vite's transform pipeline (raw Node import, a precompiled file not run through Vite). The throw fires from the default import meta's `glob()` stub.","commonSituations":"Refactors that extract `import.meta.glob` into a helper. Loading a file via the runner that bypassed Vite transformation. Third-party code that tries to feature-detect `import.meta.glob`.","solutions":["Always call `import.meta.glob(...)` by its full name inline at the use site so Vite's transform can see and replace it.","If you need a reusable helper, write a wrapper module that calls `import.meta.glob` and re-exports the result - do not pass the function itself around.","Ensure the file is actually transformed by Vite (imported through the Vite module graph, not read via raw fs/Node)."],"exampleFix":"// before - aliased, transform cannot see it\nconst glob = import.meta.glob\nconst mods = glob('./pages/*.vue')\n\n// after - inline full name\nconst mods = import.meta.glob('./pages/*.vue')","handlingStrategy":"validation","validationCode":"// Lint: flag aliasing/indirection of import.meta.glob in runner-executed code\nfunction hasAliasedImportMetaGlob(src: string): boolean {\n  return /(?:const|let|var)\\s+\\w+\\s*=\\s*import\\.meta\\.glob\\b/.test(src)\n    || /import\\.meta\\.glob\\b(?!\\s*\\()/.test(src)\n}","typeGuard":null,"tryCatchPattern":"try {\n  import.meta.glob('./pages/*.vue')\n} catch (e) {\n  if (e instanceof Error && /import.meta.glob.*statically replaced/.test(e.message)) {\n    // rewrite call site to use the full name inline\n  } else throw e\n}","preventionTips":["Always write import.meta.glob(...) inline at the call site - never alias or pass it as a value.","If you need a helper, wrap the result (the map), not the function itself."],"tags":["module-runner","import-meta-glob","transform","ssr"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}