vitejs/vite · error · SyntaxError

[vite] The requested module

Error message

[vite] The requested module '${rawId}' does not provide an export named '${lastBinding}'

What it means

Thrown by analyzeImportedModDifference() during SSR when a named import references an export that does not exist on an ESM dependency. Vite transforms SSR imports to dynamic imports for live binding/HMR, so it manually reproduces the SyntaxError Node.js would raise for a missing named export from an ESM module.

Solutions

  1. Verify the export name against the dependency's actual .d.ts or package exports (check the version you resolved).
  2. Use the default import when the package only exports default: import pkg from 'pkg' then access pkg.foo.
  3. Pin or upgrade the dependency to a version that has the named export you need.
  4. For CommonJS deps, import via default and destructure (the sibling error message at ssrTransform.ts:49 guides this).

Example fix

// before
import { defualt } from 'pkg' // typo, throws
// after
import { default } from 'pkg'
Defensive patterns

Strategy: validation

Validate before calling

// verify named exports exist before relying on them at runtime
const mod = await import('pkg')
const needed = ['foo']
const missing = needed.filter(k => !(k in mod))
if (missing.length) throw new Error(`pkg is missing exports: ${missing.join(', ')}`)

Type guard

function hasNamedExport(mod: any, name: string): boolean {
  return name in mod || name in (mod.__esModule ? mod : {})
}

Try / catch

try {
  await import('pkg')
} catch (e) {
  if (e instanceof SyntaxError && /does not provide an export named/.test(e.message)) {
    // fall back to default import + destructure
    const pkg = (await import('pkg')).default
    const { foo } = pkg
  } else throw e
}

Prevention

When it happens

Trigger: SSR code does `import { foo } from 'pkg'` where pkg is an ESM module (package type 'module') and has no export named foo. The check at ssrTransform.ts:42 throws for the last missing binding found via metadata.importedNames.

Common situations: Typo in an imported name (e.g. import { defualt } instead of default). Upgrading a dependency that renamed/removed an export. Tree-shaken or conditionally-exported named exports that don't exist under the current resolve conditions. Importing a named export from a package that only has a default export.

Related errors


AI-assisted analysis of vitejs/vite@b4d66fee14 (2026-08-11). Data as JSON: /api/errors/6c37c2d36bc91fac. Report an issue: GitHub.

Appendix: source

Thrown at packages/vite/src/shared/ssrTransform.ts:43

  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;
`)
      }
    }
  }
}

View on GitHub (pinned to b4d66fee14)