{"id":"6c37c2d36bc91fac","repo":"vitejs/vite","slug":"vite-the-requested-module-rawid-does-not-pr","errorCode":null,"errorMessage":"[vite] The requested module '${rawId}' does not provide an export named '${lastBinding}'","messagePattern":"\\[vite\\] The requested module '(.+?)' does not provide an export named '(.+?)'","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"packages/vite/src/shared/ssrTransform.ts","lineNumber":43,"sourceCode":"  rawId: string,\n  moduleType: string | undefined,\n  metadata?: SSRImportMetadata,\n): void {\n  // No normalization needed if the user already dynamic imports this module\n  if (metadata?.isDynamicImport) return\n\n  // If the user named imports a specifier that can't be analyzed, error.\n  // If the module doesn't import anything explicitly, e.g. `import 'foo'` or\n  // `import * as foo from 'foo'`, we can skip.\n  if (metadata?.importedNames?.length) {\n    const missingBindings = metadata.importedNames.filter((s) => !(s in mod))\n    if (missingBindings.length) {\n      const lastBinding = missingBindings[missingBindings.length - 1]\n\n      // For invalid named exports only, similar to how Node.js errors for top-level imports.\n      // But since we transform as dynamic imports, we need to emulate the error manually.\n      if (moduleType === 'module') {\n        throw new SyntaxError(\n          `[vite] The requested module '${rawId}' does not provide an export named '${lastBinding}'`,\n        )\n      } else {\n        // For non-ESM, named imports is done via static analysis with cjs-module-lexer in Node.js.\n        // Copied from Node.js\n        throw new SyntaxError(`\\\n[vite] Named export '${lastBinding}' not found. The requested module '${rawId}' is a CommonJS module, which may not support all module.exports as named exports.\nCommonJS modules can always be imported via the default export, for example using:\n\nimport pkg from '${rawId}';\nconst {${missingBindings.join(', ')}} = pkg;\n`)\n      }\n    }\n  }\n}\n","sourceCodeStart":25,"sourceCodeEnd":60,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/shared/ssrTransform.ts#L25-L60","documentation":"During SSR, Vite rewrites static imports into __vite_ssr_import__ calls and then validates that every named binding the user imported actually exists on the loaded module. For ESM ('module' type) modules, if a named binding is missing, Vite manually throws a SyntaxError mirroring Node.js's native top-level-import error, because SSR transforms imports as dynamic imports and Node would not check named bindings at that point. This emulates correct ESM strictness.","triggerScenarios":"An SSR import statement like `import { foo } from './mod'` where './mod' is an ESM module that does not export 'foo'. The analyzeImportedModDifference function detects the missing binding via metadata.importedNames and throws. Only triggered for static (non-dynamic) imports of ESM modules.","commonSituations":"Importing a named export that was renamed, removed, or never existed in an ESM dependency. Tree-shaking or a version bump that removed an export. Typo in the import binding name. Importing from an ESM module that only has a default export.","solutions":["Check the actual exports of the module named in the error (rawId) and use a binding that exists.","If the export was renamed in a new version, update the import to the new name.","If only a default export exists, use `import mod from 'rawId'` instead of a named import."],"exampleFix":"// before\nimport { foo } from './mod' // './mod' has no 'foo' export\n\n// after — use the correct export name (or default)\nimport { correctName } from './mod'\n// or\nimport mod from './mod'\nconst { foo } = mod","handlingStrategy":"type-guard","validationCode":"// Before relying on a named import in SSR, verify the export exists\nimport * as knownExports from './mod'\nconst needed = 'foo'\nif (!(needed in knownExports)) {\n  throw new Error(`'./mod' does not export '${needed}'`)\n}","typeGuard":"// Runtime check that a binding exists on a loaded module\nfunction hasExport(mod: Record<string, any>, name: string): boolean {\n  return name in mod\n}","tryCatchPattern":"try {\n  await ssrLoadModule(url)\n} catch (e) {\n  if (e instanceof SyntaxError && /does not provide an export named/.test(e.message)) {\n    // fix the import binding in the source file named in the error\n  } else {\n    throw e\n  }\n}","preventionTips":["Match import binding names exactly to the module's declared exports.","After upgrading an ESM dependency, re-check its exported names.","Use editor/TS tooling to verify named imports against type declarations."],"tags":["ssr","esm","imports","named-exports"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}