Home / Function/ createImportMetaResolver() — vite Function Reference

createImportMetaResolver() — vite Function Reference

Architecture documentation for the createImportMetaResolver() function in importMetaResolver.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  10f1d8d4_c841_b248_e3e8_0c71d1233d7b["createImportMetaResolver()"]
  87fdb861_d26b_9010_7a55_34478977224c["importMetaResolver.ts"]
  10f1d8d4_c841_b248_e3e8_0c71d1233d7b -->|defined in| 87fdb861_d26b_9010_7a55_34478977224c
  10bfbafa_a521_4af3_65ac_37766f7c7a81["createNodeImportMeta()"]
  10bfbafa_a521_4af3_65ac_37766f7c7a81 -->|calls| 10f1d8d4_c841_b248_e3e8_0c71d1233d7b
  f7f3ac4c_520c_5890_698f_e1be179267d2["bundleConfigFile()"]
  f7f3ac4c_520c_5890_698f_e1be179267d2 -->|calls| 10f1d8d4_c841_b248_e3e8_0c71d1233d7b
  style 10f1d8d4_c841_b248_e3e8_0c71d1233d7b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/module-runner/importMetaResolver.ts lines 41–88

export function createImportMetaResolver(): ImportMetaResolver | undefined {
  if (isHookRegistered) {
    return importMetaResolveWithCustomHook
  }

  let module: typeof import('node:module') | undefined
  try {
    module =
      typeof process !== 'undefined'
        ? process.getBuiltinModule('node:module').Module
        : undefined
  } catch {
    return
  }
  // `module.Module` may be `undefined` when `node:module` is mocked
  if (!module) {
    return
  }

  // Use registerHooks if available as it's more performant
  // eslint-disable-next-line n/no-unsupported-features/node-builtins -- we check the existence
  if (module.registerHooks) {
    // eslint-disable-next-line n/no-unsupported-features/node-builtins -- we checked the existence
    module.registerHooks({ resolve: customizationHookResolve })
    isHookRegistered = true
    return importMetaResolveWithCustomHook
  }

  // eslint-disable-next-line n/no-unsupported-features/node-builtins -- we check the existence
  if (!module.register) {
    return
  }

  try {
    const hookModuleContent = `data:text/javascript,${encodeURI(customizationHooksModule)}`
    // eslint-disable-next-line n/no-unsupported-features/node-builtins -- we checked the existence
    module.register(hookModuleContent)
  } catch (e) {
    // For `--experimental-network-imports` flag that exists in Node before v22
    if ('code' in e && e.code === 'ERR_NETWORK_IMPORT_DISALLOWED') {
      return
    }
    throw e
  }

  isHookRegistered = true
  return importMetaResolveWithCustomHook
}

Domain

Subdomains

Frequently Asked Questions

What does createImportMetaResolver() do?
createImportMetaResolver() is a function in the vite codebase, defined in packages/vite/src/module-runner/importMetaResolver.ts.
Where is createImportMetaResolver() defined?
createImportMetaResolver() is defined in packages/vite/src/module-runner/importMetaResolver.ts at line 41.
What calls createImportMetaResolver()?
createImportMetaResolver() is called by 2 function(s): bundleConfigFile, createNodeImportMeta.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free