{"record":{"id":"a7224b1dfe60643e","repo":"withastro/astro","slug":"no-cached-compile-metadata-found-for-id-the","errorCode":null,"errorMessage":"No cached compile metadata found for \"${id}\". The main Astro module \"${filename}\" should have compiled and filled the metadata first, before its virtual modules can be requested.","messagePattern":"No cached compile metadata found for \"(.+?)\"\\. The main Astro module \"(.+?)\" should have compiled and filled the metadata first, before its virtual modules can be requested\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/astro/src/vite-plugin-astro/index.ts","lineNumber":158,"sourceCode":"\t\t\t\t\t// through the metadata from `astroFileToCompileMetadata`. It should always exist as Astro\n\t\t\t\t\t// modules are compiled first, then its virtual modules.\n\t\t\t\t\tconst filename = normalizePath(normalizeFilename(parsedId.filename, config.root));\n\t\t\t\t\tlet compileMetadata = astroFileToCompileMetadata.get(filename);\n\t\t\t\t\tif (!compileMetadata) {\n\t\t\t\t\t\t// If `compileMetadata` doesn't exist in dev, that means the virtual module may have been invalidated.\n\t\t\t\t\t\t// We try to re-compile the main Astro module (`filename`) first before retrieving the metadata again.\n\t\t\t\t\t\tif (server) {\n\t\t\t\t\t\t\tconst code = await loadId(server.pluginContainer, filename);\n\t\t\t\t\t\t\t// `compile` should re-set `filename` in `astroFileToCompileMetadata`\n\t\t\t\t\t\t\tif (code != null) await compile(code, filename);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tcompileMetadata = astroFileToCompileMetadata.get(filename);\n\t\t\t\t\t}\n\t\t\t\t\t// If the metadata still doesn't exist, that means the virtual modules are somehow compiled first,\n\t\t\t\t\t// throw an error and we should investigate it.\n\t\t\t\t\tif (!compileMetadata) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`No cached compile metadata found for \"${id}\". The main Astro module \"${filename}\" should have ` +\n\t\t\t\t\t\t\t\t`compiled and filled the metadata first, before its virtual modules can be requested.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tswitch (query.type) {\n\t\t\t\t\t\tcase 'style': {\n\t\t\t\t\t\t\tif (typeof query.index === 'undefined') {\n\t\t\t\t\t\t\t\tthrow new Error(`Requests for Astro CSS must include an index.`);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst result = compileMetadata.css[query.index];\n\t\t\t\t\t\t\tif (!result) {\n\t\t\t\t\t\t\t\tthrow new Error(`No Astro CSS at index ${query.index}`);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Register dependencies from preprocessing this style\n\t\t\t\t\t\t\tresult.dependencies?.forEach((dep) => this.addWatchFile(dep));","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/withastro/astro/blob/52e6c34790cc8ac4e69e6135ace06049867e5c4a/packages/astro/src/vite-plugin-astro/index.ts#L140-L176","documentation":"Astro's compiler caches per-file metadata (scripts, styles) in an in-memory map when a .astro module compiles, and virtual sub-modules such as file.astro?astro&type=style&index=0 or ...&type=script read from that cache. This error is thrown when such a virtual module is requested before its parent .astro file has compiled — including after the plugin forces a recompile of the parent. It signals a module-graph ordering problem, normally prevented because Vite loads the parent first.","triggerScenarios":"A custom plugin importing *.astro?astro&type=... URLs directly; deleting node_modules/.vite while the dev server is running; HMR after renaming or moving a .astro file leaving a stale graph; cached transforms from an older Astro version mixed with a newer one.","commonSituations":"Writing Vite plugins that scan or import Astro virtual modules; CI caches of .vite surviving an Astro upgrade; flaky HMR after large refactors with the dev server running.","solutions":["Restart the dev server so the module graph is rebuilt in dependency order","With the server stopped, delete node_modules/.vite (and .astro data), then start again","If a custom plugin imports .astro?astro&type=... ids, import the parent .astro module instead and let Astro resolve its virtual sub-modules","Report a minimal reproduction if it recurs on a clean cache with current versions"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// custom plugins that touch astro virtual modules\ntry {\n\tconst code = await loadId(server.pluginContainer, id);\n} catch (err) {\n\tif (err instanceof Error && err.message.includes('No cached compile metadata')) {\n\t\t// import the parent .astro module first so it compiles, then retry the virtual id\n\t\tawait loadId(server.pluginContainer, filename);\n\t\treturn loadId(server.pluginContainer, id);\n\t}\n\tthrow err;\n}","preventionTips":["Never import *.astro?astro&type=... virtual URLs from your own plugins — import the parent .astro file","Delete node_modules/.vite only while the dev server is stopped","Clear caches and restart after upgrading Astro to avoid mixing transform versions"],"tags":["vite","virtual-modules","dev-server","cache"],"backgroundTag":"vite-module-cache-miss","analyzedSha":"52e6c34790cc8ac4e69e6135ace06049867e5c4a","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}