Home / Function/ analyzeImportedModDifference() — vite Function Reference

analyzeImportedModDifference() — vite Function Reference

Architecture documentation for the analyzeImportedModDifference() function in ssrTransform.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  0d6c59ba_8e92_3008_e3b8_8fe33b44bf4c["analyzeImportedModDifference()"]
  e5afda66_d325_b39d_895d_9edd47b6bafd["ssrTransform.ts"]
  0d6c59ba_8e92_3008_e3b8_8fe33b44bf4c -->|defined in| e5afda66_d325_b39d_895d_9edd47b6bafd
  5545fcba_59d0_ba73_89b7_11f4c41391bd["processImport()"]
  5545fcba_59d0_ba73_89b7_11f4c41391bd -->|calls| 0d6c59ba_8e92_3008_e3b8_8fe33b44bf4c
  style 0d6c59ba_8e92_3008_e3b8_8fe33b44bf4c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/shared/ssrTransform.ts lines 23–59

export function analyzeImportedModDifference(
  mod: any,
  rawId: string,
  moduleType: string | undefined,
  metadata?: SSRImportMetadata,
): void {
  // No normalization needed if the user already dynamic imports this module
  if (metadata?.isDynamicImport) return

  // If the user named imports a specifier that can't be analyzed, error.
  // If the module doesn't import anything explicitly, e.g. `import 'foo'` or
  // `import * as foo from 'foo'`, we can skip.
  if (metadata?.importedNames?.length) {
    const missingBindings = metadata.importedNames.filter((s) => !(s in mod))
    if (missingBindings.length) {
      const lastBinding = missingBindings[missingBindings.length - 1]

      // For invalid named exports only, similar to how Node.js errors for top-level imports.
      // But since we transform as dynamic imports, we need to emulate the error manually.
      if (moduleType === 'module') {
        throw new SyntaxError(
          `[vite] The requested module '${rawId}' does not provide an export named '${lastBinding}'`,
        )
      } else {
        // For non-ESM, named imports is done via static analysis with cjs-module-lexer in Node.js.
        // Copied from Node.js
        throw new SyntaxError(`\
[vite] Named export '${lastBinding}' not found. The requested module '${rawId}' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '${rawId}';
const {${missingBindings.join(', ')}} = pkg;
`)
      }
    }
  }
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does analyzeImportedModDifference() do?
analyzeImportedModDifference() is a function in the vite codebase, defined in packages/vite/src/shared/ssrTransform.ts.
Where is analyzeImportedModDifference() defined?
analyzeImportedModDifference() is defined in packages/vite/src/shared/ssrTransform.ts at line 23.
What calls analyzeImportedModDifference()?
analyzeImportedModDifference() is called by 1 function(s): processImport.

Analyze Your Own Codebase

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

Try Supermodel Free