{"record":{"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/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/module-runner/runner.ts#L345-L381","documentation":"In `directRequest`, after fetching module metadata the runner reads `fetchResult.code`. If `code == null` (and the module is not externalized), the runner cannot evaluate it and throws a load-failure error, including the importing module for context. The root cause is the transport returning a fetch result with no code.","triggerScenarios":"The runner transport's `fetchModule` returns a result whose `code` is null/undefined for a non-externalized module. This happens when the dev server fails to transform a file, the file is unreadable, or a custom transport returns an empty result.","commonSituations":"Importing a file that errors during transformation (syntax error, unsupported syntax) where the server swallows the transform error and returns empty code. Network/filesystem issues in a remote transport. Misbehaving plugin `load` hooks returning null.","solutions":["Check the dev server logs for the transform error of the named module and fix the underlying syntax/transform error.","If using a custom transport, ensure `fetchModule` throws on real errors instead of returning `{ code: null }`.","Verify the module path (`url`) resolves to a real, readable file.","Disable plugins one-by-one to find a `load`/`transform` hook returning null for that module."],"exampleFix":"// before (custom transport)\nasync invoke('fetchModule', [url]) {\n  try { return { code: await readFileMaybe(url), url } }\n  catch { return { code: null, url } } // hides the error\n}\n// after\nasync invoke('fetchModule', [url]) {\n  const code = await fs.readFile(url, 'utf-8') // throws on missing - surfaces real error\n  return { code, url }\n}","handlingStrategy":"try-catch","validationCode":"function assertFetchResultHasCode(result: unknown, url: string) {\n  if (!result || typeof result !== 'object') return\n  if (!('externalize' in result) && (result as any).code == null) {\n    throw new Error(`fetchModule returned no code for ${url} - check transform/load errors`)\n  }\n}","typeGuard":"function isFetchResultWithCode(r: any): boolean {\n  return r && ('externalize' in r || typeof r.code === 'string')\n}","tryCatchPattern":"try {\n  return await runner.import(url)\n} catch (e) {\n  if (e instanceof Error && /Failed to load/.test(e.message)) {\n    // inspect dev-server logs for the transform error on the named module; do not blindly retry\n  } else throw e\n}","preventionTips":["Surface transform errors in custom transports (throw, don't return { code: null }).","Watch the dev-server console for the real transform error behind a 'Failed to load'."],"tags":["module-runner","load-failure","transport","transform","ssr"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}