Skip to content

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

Merged
ascorbic merged 5 commits intomainfrom
fix/virtual-module-optimizedeps
Apr 1, 2026
Merged

fix: exclude virtual:emdash from optimizeDeps to fix npm installs on Cloudflare#2
ascorbic merged 5 commits intomainfrom
fix/virtual-module-optimizedeps

Conversation

@ascorbic
Copy link
Copy Markdown
Collaborator

@ascorbic ascorbic commented Apr 1, 2026

Summary

  • Fixes Could not resolve "virtual:emdash/*" errors when emdash is installed from npm (not workspace link) on Cloudflare
  • Adds "virtual:emdash" to optimizeDeps.exclude in both ssr.optimizeDeps (Cloudflare) and root optimizeDeps

Problem

When emdash is installed from npm, the dist files contain externalized virtual:emdash/* import specifiers (e.g. import("virtual:emdash/seed")). These are intentionally left as bare specifiers by tsdown -- they're resolved by the Vite virtual module plugin at the user's site build/dev time.

However, Vite's esbuild-based dependency pre-bundler (optimizeDeps) crawls emdash's dist files when pre-bundling its dependencies (the emdash > kysely, emdash > jose, etc. entries). During this crawl, esbuild encounters the virtual:emdash/* imports and fails because it has no plugin to resolve them.

In the monorepo this doesn't happen because emdash resolves to the workspace source, where Vite processes files through its transform pipeline (which includes the virtual module plugin) rather than through esbuild's pre-bundler.

The @astrojs/cloudflare adapter already excludes Astro's own virtual modules (astro:*, virtual:astro:*) from the optimizer, but virtual:emdash wasn't listed.

How it works

Vite's optimizeDeps.exclude matching uses prefix comparison: id.startsWith(entry + "/"). So "virtual:emdash" matches all "virtual:emdash/config", "virtual:emdash/seed", "virtual:emdash/dialect", etc.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 1, 2026

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/admin@2

@emdash-cms/auth

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/auth@2

@emdash-cms/blocks

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/blocks@2

@emdash-cms/cloudflare

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/cloudflare@2

emdash

npm i https://pkg.pr.new/emdash-cms/emdash@2

create-emdash

npm i https://pkg.pr.new/emdash-cms/emdash/create-emdash@2

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/gutenberg-to-portable-text@2

@emdash-cms/x402

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/x402@2

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-ai-moderation@2

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-atproto@2

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-audit-log@2

@emdash-cms/plugin-color

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-color@2

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-embeds@2

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-forms@2

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-webhook-notifier@2

commit: 9f14710

ascorbic added 4 commits April 1, 2026 12:39
Miniflare asserts database_id is truthy. An empty string crashes
on startup. Use 'local' as a placeholder -- miniflare doesn't
validate it for local dev, and the comment tells users to replace
it with a real ID for deploy.
@ascorbic ascorbic merged commit 1500cd4 into main Apr 1, 2026
16 of 17 checks passed
travisbreaks pushed a commit to travisbreaks/emdash that referenced this pull request Apr 5, 2026
…timizedeps

fix: exclude virtual:emdash from optimizeDeps to fix npm installs on Cloudflare
jdevalk added a commit to jdevalk/emdash that referenced this pull request Apr 7, 2026
- Fix emdash-cms#1: Use @phosphor-icons/react instead of lucide-react
- Fix emdash-cms#2: Send minimal patch { image } instead of spreading stale seo props
- Fix emdash-cms#3: Only show OG Image next to the featured_image field, not all image fields
- Fix emdash-cms#4: Only add description text for the featured_image field
- Fix emdash-cms#5: Add responsive breakpoint (grid-cols-1 md:grid-cols-2)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ascorbic added a commit that referenced this pull request Apr 7, 2026
* Add OG Image field to content editor

The `_emdash_seo` table and content API already support `seo_image`, but
the admin UI had no way to set it. This adds:

- `SeoImageField` component using the existing `MediaPickerModal`
- 2-column grid layout placing the OG Image next to the Featured Image
- `description` prop on `ImageFieldRenderer` for helper text below images
- Preserve `seo.image` in `SeoPanel.emitChange` so sidebar edits don't
  clear the image

Closes #327

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* style: format

* Add changeset and fix stale seo.image in SeoPanel

- Add changeset for @emdash-cms/admin patch release
- Remove image from SeoPanel.emitChange to avoid overwriting
  a freshly-selected OG image with a stale prop value

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Address review feedback on OG Image field

- Fix #1: Use @phosphor-icons/react instead of lucide-react
- Fix #2: Send minimal patch { image } instead of spreading stale seo props
- Fix #3: Only show OG Image next to the featured_image field, not all image fields
- Fix #4: Only add description text for the featured_image field
- Fix #5: Add responsive breakpoint (grid-cols-1 md:grid-cols-2)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* style: format

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: emdashbot[bot] <emdashbot[bot]@users.noreply.github.com>
Co-authored-by: Matt Kane <mkane@cloudflare.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant