vitejs/vite · error · Error
[module runner] Failed to load "${url}"${importer ? ` import
Error message
[module runner] Failed to load "${url}"${importer ? ` imported from ${importer}` : ''} What it means
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.
Source
Thrown at packages/vite/src/module-runner/runner.ts:363
if (dep[0] === '.') {
dep = posixResolve(posixDirname(url), dep)
}
return request(dep, { isDynamicImport: true })
}
if ('externalize' in fetchResult) {
const { externalize } = fetchResult
this.debug?.('[module runner] externalizing', externalize)
const exports = await this.evaluator.runExternalModule(externalize)
mod.exports = exports
return exports
}
const { code, file } = fetchResult
if (code == null) {
const importer = callstack[callstack.length - 2]
throw new Error(
`[module runner] Failed to load "${url}"${
importer ? ` imported from ${importer}` : ''
}`,
)
}
const createImportMeta =
this.options.createImportMeta ?? createDefaultImportMeta
const modulePath = cleanUrl(file || moduleId)
// disambiguate the `<UNIT>:/` on windows: see nodejs/node#31710
const href = posixPathToFileHref(modulePath)
const meta = await createImportMeta(modulePath)
const exports = Object.create(null)
Object.defineProperty(exports, Symbol.toStringTag, {
value: 'Module',
enumerable: false,
configurable: false,View on GitHub (pinned to 89620f09af)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
// Validate the module URL is resolvable before importing
async function validateModuleExists(server, url) {
// use the server's transformRequest or module graph to check
const mod = server.moduleGraph.getModuleById(url)
if (!mod) {
console.warn(`Module ${url} not found in module graph — import may fail`)
}
return !!mod
} Type guard
function isValidModuleUrl(url: string): boolean {
// basic validation: non-empty, valid path
return typeof url === 'string' && url.length > 0 && !url.includes('\0null')
} Try / catch
try {
await runner.import(url)
} catch (e) {
if (e.message.includes('Failed to load')) {
console.error(`Module not found or transform failed: ${url}`)
console.error('Check: file exists, virtual module plugin is loaded, no transform errors')
}
throw e
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- [module runner] Dynamic access of "import.meta.env" is not s
- [module runner] "import.meta.resolve" is not supported.
- [module runner] "import.meta.glob" is statically replaced du
- HMR is not supported by this runner transport, but `hmr` opt
- Vite module runner has been closed.
AI-assisted analysis of vitejs/vite@89620f09af (2026-08-03).
Data as JSON: /data/errors/0edd474c7d15ba47.json.
Report an issue: GitHub.