Home / Function/ needsInterop() — vite Function Reference

needsInterop() — vite Function Reference

Architecture documentation for the needsInterop() function in index.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  77c60311_65fe_efad_3869_31b3a53d27e3["needsInterop()"]
  2f328851_91ee_fb05_63f0_4f466b9d6250["index.ts"]
  77c60311_65fe_efad_3869_31b3a53d27e3 -->|defined in| 2f328851_91ee_fb05_63f0_4f466b9d6250
  b53437fa_d2e4_a560_0d14_dfc84f740176["runOptimizeDeps()"]
  b53437fa_d2e4_a560_0d14_dfc84f740176 -->|calls| 77c60311_65fe_efad_3869_31b3a53d27e3
  d7d28d2f_0a7a_bed9_0e0f_6db71b4e1368["optimizedDepNeedsInterop()"]
  d7d28d2f_0a7a_bed9_0e0f_6db71b4e1368 -->|calls| 77c60311_65fe_efad_3869_31b3a53d27e3
  df3a0cc2_d23e_314f_e952_5b3b3e91b60f["isSingleDefaultExport()"]
  77c60311_65fe_efad_3869_31b3a53d27e3 -->|calls| df3a0cc2_d23e_314f_e952_5b3b3e91b60f
  style 77c60311_65fe_efad_3869_31b3a53d27e3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/optimizer/index.ts lines 1172–1201

function needsInterop(
  environment: Environment,
  id: string,
  exportsData: ExportsData,
  output?: { exports: string[] },
): boolean {
  if (environment.config.optimizeDeps.needsInterop?.includes(id)) {
    return true
  }
  const { hasModuleSyntax, exports } = exportsData
  // entry has no ESM syntax - likely CJS or UMD
  if (!hasModuleSyntax) {
    return true
  }

  if (output) {
    // if a peer dependency used require() on an ESM dependency, esbuild turns the
    // ESM dependency's entry chunk into a single default export... detect
    // such cases by checking exports mismatch, and force interop.
    const generatedExports: string[] = output.exports

    if (
      isSingleDefaultExport(generatedExports) &&
      !isSingleDefaultExport(exports)
    ) {
      return true
    }
  }
  return false
}

Subdomains

Frequently Asked Questions

What does needsInterop() do?
needsInterop() is a function in the vite codebase, defined in packages/vite/src/node/optimizer/index.ts.
Where is needsInterop() defined?
needsInterop() is defined in packages/vite/src/node/optimizer/index.ts at line 1172.
What does needsInterop() call?
needsInterop() calls 1 function(s): isSingleDefaultExport.
What calls needsInterop()?
needsInterop() is called by 2 function(s): optimizedDepNeedsInterop, runOptimizeDeps.

Analyze Your Own Codebase

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

Try Supermodel Free