vitejs/vite · error · Error
[vite] transform failed for module '${url}' imported from '$
Error message
[vite] transform failed for module '${url}' imported from '${importer}'. What it means
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.
Source
Thrown at packages/vite/src/node/ssr/fetchModule.ts:94
? 'module'
: 'commonjs'
return { externalize: file, type }
}
url = unwrapId(url)
const mod = await environment.moduleGraph.ensureEntryFromUrl(url)
const cached = !!mod.transformResult
// if url is already cached, we can just confirm it's also cached on the server
if (options.cached && cached) {
return { cache: true }
}
let result = await environment.transformRequest(url)
if (!result) {
throw new Error(
`[vite] transform failed for module '${url}'${
importer ? ` imported from '${importer}'` : ''
}.`,
)
}
if (options.inlineSourceMap !== false) {
result = inlineSourceMap(mod, result, options.startOffset)
}
// remove shebang
if (result.code[0] === '#')
result.code = result.code.replace(/^#!.*/, (s) => ' '.repeat(s.length))
return {
code: result.code,
file: mod.file,
id: mod.id!,View on GitHub (pinned to b4d66fee14)
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.
Example fix
// The message names the failing url and importer.
// Fix the root cause in that file, e.g.:
// before (module.ts)
export const x = { a: 1 // syntax error
// after
export const x = { a: 1 } Defensive patterns
Strategy: try-catch
Try / catch
try {
await server.ssrLoadModule(url)
} catch (e) {
if (String(e?.message).startsWith('[vite] transform failed')) {
// surface the earlier transform error, fix the source module
console.error(e)
}
throw e
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- [module runner] "import.meta.glob" is statically replaced du
- [module runner] Failed to load "${url}"${importer ? ` import
- [module runner] Dynamic access of "import.meta.env" is not s
- [module runner] "import.meta.resolve" is not supported.
- Module "${url}" was mistakenly invalidated during fetch phas
AI-assisted analysis of vitejs/vite@b4d66fee14 (2026-08-11).
Data as JSON: /api/errors/02221f30150f02b8.
Report an issue: GitHub.