Skip to content

Commit f19d3b5

Browse files
authored
fix: CSS imports in Worker modules causing dev server to crash when starting up (#11404)
* Import CSS in assets playground to cause test failure * Call pluginContainer.buildStart() for the client environment before making requests * Add changeset
1 parent d524e55 commit f19d3b5

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

.changeset/nasty-jobs-tan.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/vite-plugin": patch
3+
---
4+
5+
fix: CSS imports in Worker modules causing dev server to crash when starting up
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background-color: red;
3+
}

packages/vite-plugin-cloudflare/playground/assets/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import html from "./index.html?raw";
22
import importedImage from "./imported-image.svg";
33
import importedText from "./imported-text.txt?url";
44
import inlineImage from "./inline-image.svg?inline";
5+
// Import CSS to ensure this doesn't cause errors
6+
import "./index.css";
57

68
interface Env {
79
ASSETS: Fetcher;

packages/vite-plugin-cloudflare/src/export-types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ export async function getCurrentWorkerNameToExportTypesMap(
159159
viteDevServer: vite.ViteDevServer,
160160
miniflare: Miniflare
161161
): Promise<Map<string, ExportTypes>> {
162+
// Vite's internal CSS plugins rely on `buildStart` being called for the client environment before modules are transformed in server environments
163+
// Vite calls this method when initialising the dev server but we need to make requests before that happens
164+
await viteDevServer.environments.client.pluginContainer.buildStart();
165+
162166
const results = await Promise.all(
163167
[...resolvedPluginConfig.environmentNameToWorkerMap].map(
164168
async ([environmentName, worker]) => {

0 commit comments

Comments
 (0)