fix: exclude virtual:emdash from optimizeDeps to fix npm installs on Cloudflare
This commit is contained in:
5
.changeset/fix-virtual-module-optimizedeps.md
Normal file
5
.changeset/fix-virtual-module-optimizedeps.md
Normal 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.
|
||||||
@@ -269,6 +269,13 @@ export function createViteConfig(
|
|||||||
// Vite discovers them one-by-one on first request, causing workerd
|
// Vite discovers them one-by-one on first request, causing workerd
|
||||||
// to enter "worker cancelled" state on cold cache.
|
// to enter "worker cancelled" state on cold cache.
|
||||||
optimizeDeps: {
|
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: [
|
include: [
|
||||||
// EmDash direct deps
|
// EmDash direct deps
|
||||||
"emdash > @portabletext/toolkit",
|
"emdash > @portabletext/toolkit",
|
||||||
@@ -322,7 +329,7 @@ export function createViteConfig(
|
|||||||
include: useSource
|
include: useSource
|
||||||
? ["@astrojs/react/client.js"]
|
? ["@astrojs/react/client.js"]
|
||||||
: ["@emdash-cms/admin", "@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"],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user