diff --git a/packages/astro/src/content/types-generator.ts b/packages/astro/src/content/types-generator.ts index 973a892fa17f..faf02d95d915 100644 --- a/packages/astro/src/content/types-generator.ts +++ b/packages/astro/src/content/types-generator.ts @@ -590,11 +590,9 @@ async function writeContentFiles({ // If it's the first time, we inject types the usual way. sync() will handle creating files and references. If it's not the first time, we just override the dts content if (settings.injectedTypes.some((t) => t.filename === CONTENT_TYPES_FILE)) { - fs.promises.writeFile( - new URL(CONTENT_TYPES_FILE, settings.dotAstroDir), - typeTemplateContent, - 'utf-8', - ); + const filePath = fileURLToPath(new URL(CONTENT_TYPES_FILE, settings.dotAstroDir)); + await fs.promises.mkdir(path.dirname(filePath), { recursive: true }); + await fs.promises.writeFile(filePath, typeTemplateContent, 'utf-8'); } else { settings.injectedTypes.push({ filename: CONTENT_TYPES_FILE,