diff --git a/.changeset/smooth-hats-smell.md b/.changeset/smooth-hats-smell.md new file mode 100644 index 000000000000..cac2f8befcaa --- /dev/null +++ b/.changeset/smooth-hats-smell.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Ensure SSR module is loaded before testing if it's CSS in dev diff --git a/packages/astro/src/core/render/dev/css.ts b/packages/astro/src/core/render/dev/css.ts index cfbfa7114d10..9c10cb03cd40 100644 --- a/packages/astro/src/core/render/dev/css.ts +++ b/packages/astro/src/core/render/dev/css.ts @@ -18,11 +18,14 @@ export async function getStylesForURL( for await (const importedModule of crawlGraph(viteServer, viteID(filePath), true)) { const ext = path.extname(importedModule.url).toLowerCase(); if (STYLE_EXTENSIONS.has(ext)) { + // The SSR module is possibly not loaded. Load it if it's null. + const ssrModule = + importedModule.ssrModule ?? (await viteServer.ssrLoadModule(importedModule.url)); if ( mode === 'development' && // only inline in development - typeof importedModule.ssrModule?.default === 'string' // ignore JS module styles + typeof ssrModule?.default === 'string' // ignore JS module styles ) { - importedStylesMap.set(importedModule.url, importedModule.ssrModule.default); + importedStylesMap.set(importedModule.url, ssrModule.default); } else { // NOTE: We use the `url` property here. `id` would break Windows. importedCssUrls.add(importedModule.url);