{"id":"0edd474c7d15ba47","repo":"vitejs/vite","slug":"module-runner-failed-to-load-url-importer","errorCode":null,"errorMessage":"[module runner] Failed to load \"${url}\"${importer ? ` imported from ${importer}` : ''}","messagePattern":"\\[module runner\\] Failed to load \"(.+?)\"(.+?)` : ''\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/module-runner/runner.ts","lineNumber":363,"sourceCode":"      if (dep[0] === '.') {\n        dep = posixResolve(posixDirname(url), dep)\n      }\n      return request(dep, { isDynamicImport: true })\n    }\n\n    if ('externalize' in fetchResult) {\n      const { externalize } = fetchResult\n      this.debug?.('[module runner] externalizing', externalize)\n      const exports = await this.evaluator.runExternalModule(externalize)\n      mod.exports = exports\n      return exports\n    }\n\n    const { code, file } = fetchResult\n\n    if (code == null) {\n      const importer = callstack[callstack.length - 2]\n      throw new Error(\n        `[module runner] Failed to load \"${url}\"${\n          importer ? ` imported from ${importer}` : ''\n        }`,\n      )\n    }\n\n    const createImportMeta =\n      this.options.createImportMeta ?? createDefaultImportMeta\n\n    const modulePath = cleanUrl(file || moduleId)\n    // disambiguate the `<UNIT>:/` on windows: see nodejs/node#31710\n    const href = posixPathToFileHref(modulePath)\n    const meta = await createImportMeta(modulePath)\n    const exports = Object.create(null)\n    Object.defineProperty(exports, Symbol.toStringTag, {\n      value: 'Module',\n      enumerable: false,\n      configurable: false,","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/vite/src/module-runner/runner.ts#L345-L381","documentation":"Thrown in directRequest when the fetched module result has null/undefined code. The module runner successfully fetched metadata for the URL (the transport returned a result), but the actual code field is missing. This means the server couldn't provide the transformed source for the requested module — the file doesn't exist, couldn't be read, failed to transform, or was otherwise unavailable.","triggerScenarios":"Importing a URL that doesn't resolve to any file on the server. A transform error during fetchModule that results in a response with no code. A transport that returns a malformed fetch result (missing code field). Importing a virtual module that the server doesn't handle.","commonSituations":"Importing a non-existent module path in SSR code. A file was deleted or renamed but code still imports it. A Vite plugin that should provide a virtual module via resolveId/load is missing or misconfigured. Network or serialization issues in custom transports that drop the code field.","solutions":["Verify the module URL/path exists and is resolvable by the Vite dev server — check for typos, wrong extensions, or missing files.","If importing a virtual module (e.g., virtual:my-plugin), ensure the plugin that provides it is loaded and its resolveId/load hooks are correct.","Debug the transport's fetchModule response to confirm the server is returning code; log the fetch result before the error point.","Check the Vite dev server logs for transform errors on the specific module."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Validate the module URL is resolvable before importing\nasync function validateModuleExists(server, url) {\n  // use the server's transformRequest or module graph to check\n  const mod = server.moduleGraph.getModuleById(url)\n  if (!mod) {\n    console.warn(`Module ${url} not found in module graph — import may fail`)\n  }\n  return !!mod\n}","typeGuard":"function isValidModuleUrl(url: string): boolean {\n  // basic validation: non-empty, valid path\n  return typeof url === 'string' && url.length > 0 && !url.includes('\\0null')\n}","tryCatchPattern":"try {\n  await runner.import(url)\n} catch (e) {\n  if (e.message.includes('Failed to load')) {\n    console.error(`Module not found or transform failed: ${url}`)\n    console.error('Check: file exists, virtual module plugin is loaded, no transform errors')\n  }\n  throw e\n}","preventionTips":["Verify module paths exist and are correct before importing in SSR code.","Ensure all virtual module plugins are properly configured and loaded.","Check Vite dev server logs for transform errors on imported modules.","Implement custom transport fetchModule logging to inspect server responses during development."],"tags":["module-runner","module-loading","ssr","transport","missing-module"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}