{"id":"a2d8c3a0b31bdd3b","repo":"vitejs/vite","slug":"vite-internal-error-registermissingimport-is-not","errorCode":null,"errorMessage":"Vite Internal Error: registerMissingImport is not supported in dev ${environment.name}","messagePattern":"Vite Internal Error: registerMissingImport is not supported in dev (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/optimizer/optimizer.ts","lineNumber":764,"sourceCode":"      debouncedProcessing(0)\n    }\n  }\n\n  return depsOptimizer\n}\n\nexport function createExplicitDepsOptimizer(\n  environment: DevEnvironment,\n): DepsOptimizer {\n  const depsOptimizer = {\n    metadata: initDepsOptimizerMetadata(environment),\n    isOptimizedDepFile: createIsOptimizedDepFile(environment),\n    isOptimizedDepUrl: createIsOptimizedDepUrl(environment),\n    getOptimizedDepId: (depInfo: OptimizedDepInfo) =>\n      `${depInfo.file}?v=${depInfo.browserHash}`,\n\n    registerMissingImport: () => {\n      throw new Error(\n        `Vite Internal Error: registerMissingImport is not supported in dev ${environment.name}`,\n      )\n    },\n    init,\n    // noop, there is no scanning during dev SSR\n    // the optimizer blocks the server start\n    run: () => {},\n\n    close: async () => {},\n    options: environment.config.optimizeDeps,\n  }\n\n  let inited = false\n  async function init() {\n    if (inited) return\n    inited = true\n\n    depsOptimizer.metadata = await optimizeExplicitEnvironmentDeps(environment)","sourceCodeStart":746,"sourceCodeEnd":782,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/node/optimizer/optimizer.ts#L746-L782","documentation":"`createExplicitDepsOptimizer` builds a limited optimizer for environments (e.g. SSR/dev environments without a scanner) whose `registerMissingImport` is a hard error — these environments optimize only the explicitly-listed deps and cannot dynamically register a new import discovered at runtime. The throw at optimizer.ts:764 is prefixed 'Vite Internal Error' because the call should never reach it under normal use; it indicates the environment's optimizer type doesn't support lazy registration.","triggerScenarios":"An internal Vite code path (or custom Environment API consumer) calls `registerMissingImport` on an optimizer created by `createExplicitDepsOptimizer` — i.e. an environment that only supports explicit dep optimization.","commonSituations":"Using the experimental Environment API with a custom environment that doesn't run scanning; a Vite plugin or framework integration calling the optimizer's `registerMissingImport` for an SSR environment; version mismatch between Vite core and a framework's environment plugin.","solutions":["Don't call `registerMissingImport` on explicit-only optimizers — pre-list deps in `optimizeDeps.include` instead.","If you need lazy registration, use a full dev environment with a scanner (the default client environment), not the explicit optimizer.","Update the framework/Vite version — environment APIs are evolving and this contract has changed.","Report it as a Vite internal bug if you're not calling the API yourself (the message says so)."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Before calling registerMissingImport, verify the optimizer supports it:\nfunction supportsLazyRegistration(optimizer: DepsOptimizer): boolean {\n  return typeof optimizer.registerMissingImport === 'function'\n    && !String(optimizer.registerMissingImport).includes('not supported')\n}","typeGuard":"function isFullOptimizer(o: DepsOptimizer): boolean {\n  // explicit optimizer's registerMissingImport is a throwing arrow fn\n  return !/not supported/.test(o.registerMissingImport.toString())\n}","tryCatchPattern":null,"preventionTips":["Pre-list dependencies in optimizeDeps.include for environments without scanning.","Use a full (scanning) dev environment when you need lazy dep registration.","Keep Vite and framework environment plugins version-aligned."],"tags":["optimizer","environment-api","internal","ssr"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}