vitejs/vite · error · Error

[module runner] "import.meta.resolve" is not supported.

Error message

[module runner] "import.meta.resolve" is not supported.

What it means

Thrown by the default import.meta.resolve() implementation in the module runner. createDefaultImportMeta provides a resolve function that always throws because import.meta.resolve requires module resolution infrastructure that the default module runner doesn't have. Only createNodeImportMeta (used when the runner has Node.js access) provides a functional resolve via createImportMetaResolver.

Source

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

    throw new Error(
      `[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`,
    )
  },
})

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)

View on GitHub (pinned to 89620f09af)

Solutions

  1. If running in Node.js, ensure the module runner uses createNodeImportMeta by passing it as the createImportMeta option: new ModuleRunner({ ..., createImportMeta: createNodeImportMeta }).
  2. Avoid calling import.meta.resolve in code that runs in the module runner; pre-resolve paths at build time instead.
  3. If you need resolve functionality in a custom environment, provide a custom createImportMeta function that implements resolve with your runtime's resolution mechanism.

Example fix

// before — default import meta doesn't support resolve
import { ModuleRunner } from 'vite/module-runner'
const runner = new ModuleRunner({ transport, /* no createImportMeta */ })
// after — use Node import meta which supports resolve
import { ModuleRunner } from 'vite/module-runner'
import { createNodeImportMeta } from 'vite/module-runner'
const runner = new ModuleRunner({
  transport,
  createImportMeta: createNodeImportMeta
})
Defensive patterns

Strategy: validation

Validate before calling

// Check if the runner environment supports resolve before calling
function runnerSupportsResolve(runner) {
  // createNodeImportMeta provides a working resolve; default does not
  return runner.options.createImportMeta?.name === 'createNodeImportMeta'
}

// Or check at setup time
import { isBuiltin } from 'util'
const canResolve = typeof process !== 'undefined' && !!process.versions.node

Type guard

function hasResolveSupport(meta: ModuleRunnerImportMeta): boolean {
  try {
    // can't call it without throwing — check environment instead
    return typeof process !== 'undefined'
  } catch {
    return false
  }
}

Try / catch

// Wrap import.meta.resolve calls in user code
function safeResolve(id, parent) {
  try {
    return import.meta.resolve(id, parent)
  } catch (e) {
    if (e.message.includes('import.meta.resolve')) {
      // fallback: manual resolution
      return null
    }
    throw e
  }
}

Prevention

When it happens

Trigger: Code running in a module runner instance that uses the default import meta (not the Node variant) calls import.meta.resolve('./some-module'). This happens when the ModuleRunner is constructed without a custom createImportMeta option that returns a Node-capable meta, or when running in a non-Node environment (e.g., a custom runtime, worker, or sandboxed SSR).

Common situations: Using Vite's module runner in a non-standard environment (e.g., workerd, Deno, or a sandboxed eval context) where Node's require.resolve isn't available. SSR code that calls import.meta.resolve to find a file path at runtime. Libraries that use import.meta.resolve for asset resolution.

Related errors


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