fix: exclude virtual:emdash from optimizeDeps to fix npm installs on Cloudflare

This commit is contained in:
Matt Kane
2026-04-01 12:27:00 +01:00
parent 7a545979ee
commit b09bfd51ce
2 changed files with 13 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"emdash": patch
---
Fix virtual module resolution errors when emdash is installed from npm on Cloudflare. The esbuild dependency pre-bundler was encountering `virtual:emdash/*` imports while crawling dist files and failing to resolve them. These are now excluded from the optimizeDeps scan.

View File

@@ -269,6 +269,13 @@ export function createViteConfig(
// Vite discovers them one-by-one on first request, causing workerd
// to enter "worker cancelled" state on cold cache.
optimizeDeps: {
// Exclude EmDash virtual modules from esbuild's dependency
// scan. These are resolved by the Vite plugin at transform time,
// but esbuild encounters them when crawling emdash's dist files
// during pre-bundling and can't resolve them. Vite's exclude
// uses prefix matching (id.startsWith(m + "/")), so
// "virtual:emdash" matches all "virtual:emdash/*" imports.
exclude: ["virtual:emdash"],
include: [
// EmDash direct deps
"emdash > @portabletext/toolkit",
@@ -322,7 +329,7 @@ export function createViteConfig(
include: useSource
? ["@astrojs/react/client.js"]
: ["@emdash-cms/admin", "@astrojs/react/client.js"],
exclude: cloudflare ? [] : NODE_NATIVE_EXTERNALS,
exclude: cloudflare ? ["virtual:emdash"] : [...NODE_NATIVE_EXTERNALS, "virtual:emdash"],
},
};
}