vitejs/vite · error · Error

[module runner] "import.meta.glob" is statically replaced du

Error message

[module runner] "import.meta.glob" is statically replaced during file transformation. Make sure to reference it by the full name.

What it means

Thrown by the default import.meta.glob() stub in the module runner. import.meta.glob is a Vite-specific feature that is statically transformed during the build/transform phase into actual import statements. If the call reaches the module runner at runtime, it means the source file was not processed by Vite's transform pipeline (which would have replaced import.meta.glob with concrete code). This typically indicates the file bypassed transformation.

Source

Thrown at packages/vite/src/module-runner/createImportMeta.ts:30

})

export function createDefaultImportMeta(
  modulePath: string,
): ModuleRunnerImportMeta {
  const href = posixPathToFileHref(modulePath)
  const filename = modulePath
  const dirname = posixDirname(modulePath)
  return {
    filename: isWindows ? toWindowsPath(filename) : filename,
    dirname: isWindows ? toWindowsPath(dirname) : dirname,
    url: href,
    env: envProxy,
    resolve(_id: string, _parent?: string) {
      throw new Error('[module runner] "import.meta.resolve" is not supported.')
    },
    // should be replaced during transformation
    glob() {
      throw new Error(
        `[module runner] "import.meta.glob" is statically replaced during ` +
          `file transformation. Make sure to reference it by the full name.`,
      )
    },
  }
}

/**
 * Create import.meta object for Node.js.
 */
export function createNodeImportMeta(
  modulePath: string,
): ModuleRunnerImportMeta {
  const defaultMeta = createDefaultImportMeta(modulePath)
  const href = defaultMeta.url

  const importMetaResolver = createImportMetaResolver()

View on GitHub (pinned to 89620f09af)

Solutions

  1. Ensure all modules loaded by the runner go through Vite's transform pipeline (the transport should fetchModule via the Vite dev server, not read files directly).
  2. If a dependency uses import.meta.glob, either transform it (add to optimizeDeps.include or ssr.noExternal) or avoid importing it in SSR.
  3. Make sure you reference import.meta.glob by its full literal name, not through a dynamic property or alias.
  4. Check that your transport implementation calls the server's fetchModule with the correct URL.

Example fix

// before — dependency uses import.meta.glob, loaded raw in SSR
// (dependency code)
const mods = import.meta.glob('./*.ts')
// after — add the dependency to ssr.noExternal so Vite transforms it
// vite.config.ts
ssr: { noExternal: ['problematic-dep'] }
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the dependency is transformed before loading in SSR
function ensureTransformed(dep, config) {
  const noExternal = config.ssr?.noExternal ?? []
  if (!noExternal.includes(dep) && !noExternal.includes(/.*/)) {
    console.warn(`${dep} may not be transformed; import.meta.glob calls inside it will fail`)
    config.ssr = { ...config.ssr, noExternal: [...noExternal, dep] }
  }
}

Type guard

function isTransformableImport(id: string, config: ResolvedConfig): boolean {
  // node_modules deps need ssr.noExternal to be transformed
  if (id.includes('node_modules')) {
    const noExternal = config.ssr?.noExternal
    if (Array.isArray(noExternal)) {
      return noExternal.some(pattern =>
        pattern instanceof RegExp ? pattern.test(id) : id.includes(pattern)
      )
    }
    return noExternal === true
  }
  return true
}

Try / catch

// In SSR code that loads external modules
try {
  await import('some-dep')
} catch (e) {
  if (e.message.includes('import.meta.glob')) {
    console.error('Dependency not transformed. Add to ssr.noExternal.')
  }
  throw e
}

Prevention

When it happens

Trigger: A module is loaded by the runner without going through Vite's transform pipeline — e.g., a raw file read, a file served from node_modules without transform, or a misconfigured transport that fetches un-transformed source. Also possible if import.meta.glob is accessed via a computed/dynamic property name that the transformer can't statically detect.

Common situations: SSR code that imports a file from node_modules that itself uses import.meta.glob (the dependency wasn't transformed). A custom module runner transport that doesn't invoke the Vite dev server's transform. Using import.meta.glob through an alias or re-export that obscures it from static analysis.

Related errors


AI-assisted analysis of vitejs/vite@89620f09af (2026-08-03). Data as JSON: /data/errors/05baa4b0e3052cca.json. Report an issue: GitHub.