{"record":{"id":"02221f30150f02b8","repo":"vitejs/vite","slug":"vite-transform-failed-for-module-url-import","errorCode":null,"errorMessage":"[vite] transform failed for module '${url}' imported from '${importer}'.","messagePattern":"\\[vite\\] transform failed for module '(.+?)' imported from '(.+?)'\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/ssr/fetchModule.ts","lineNumber":94,"sourceCode":"      ? 'module'\n      : 'commonjs'\n    return { externalize: file, type }\n  }\n\n  url = unwrapId(url)\n\n  const mod = await environment.moduleGraph.ensureEntryFromUrl(url)\n  const cached = !!mod.transformResult\n\n  // if url is already cached, we can just confirm it's also cached on the server\n  if (options.cached && cached) {\n    return { cache: true }\n  }\n\n  let result = await environment.transformRequest(url)\n\n  if (!result) {\n    throw new Error(\n      `[vite] transform failed for module '${url}'${\n        importer ? ` imported from '${importer}'` : ''\n      }.`,\n    )\n  }\n\n  if (options.inlineSourceMap !== false) {\n    result = inlineSourceMap(mod, result, options.startOffset)\n  }\n\n  // remove shebang\n  if (result.code[0] === '#')\n    result.code = result.code.replace(/^#!.*/, (s) => ' '.repeat(s.length))\n\n  return {\n    code: result.code,\n    file: mod.file,\n    id: mod.id!,","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/vitejs/vite/blob/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/node/ssr/fetchModule.ts#L76-L112","documentation":"Thrown by fetchModule() during SSR when environment.transformRequest(url) returns null/undefined, meaning the transform pipeline produced no usable output for the module. This is a downstream symptom: the real cause (syntax error, failing plugin, unresolved import) is usually logged separately before this error.","triggerScenarios":"SSR loading a module whose transform returns null — caused by a syntax error in the file, a plugin transform hook that returned null without throwing, a failed dependency resolve, or the module being skipped. The null check is at ssr/fetchModule.ts:93.","commonSituations":"A syntax/parse error in a source file surfaced first via SSR (ssrLoadModule / module runner). A plugin whose transform hook rejects or returns null. A circular or missing dependency that makes transformRequest bail. Node ESM/CJS interop edge cases.","solutions":["Look at the error logged immediately before this one — the actual transform failure (syntax error, plugin error) is reported there.","Open the failing module (the url in the message) and fix the syntax/parse error or the bad import.","If a plugin owns the transform, ensure its transform hook throws on failure rather than returning null.","Clear node_modules/.vite cache and restart the dev server to rule out a stale transform cache."],"exampleFix":"// The message names the failing url and importer.\n// Fix the root cause in that file, e.g.:\n// before (module.ts)\nexport const x = { a: 1  // syntax error\n// after\nexport const x = { a: 1 }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await server.ssrLoadModule(url)\n} catch (e) {\n  if (String(e?.message).startsWith('[vite] transform failed')) {\n    // surface the earlier transform error, fix the source module\n    console.error(e)\n  }\n  throw e\n}","preventionTips":["Watch the dev-server console — the real transform error is logged before this one.","Validate source files compile (tsc/eslint) before SSR-loading them.","Ensure plugin transform hooks throw rather than return null on failure."],"tags":["ssr","transform","module-loading"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}