mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #644] [MERGED] fix: use dynamic WASM imports in og-font-patch for Node.js compat #739
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#739
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/644
Author: @NathanDrake2406
Created: 3/22/2026
Status: ✅ Merged
Merged: 3/23/2026
Merged by: @james-elicx
Base:
main← Head:fix/og-wasm-node-compat📝 Commits (3)
5669b0ffix: use dynamic WASM imports in og-font-patch for Node.js compatc44121bfix: move resvg new URL() inside catch handler for workerd compat3f96f21refactor: address review — remove dead atob branch, async readFile, dedup tests📊 Changes
2 files changed (+266 additions, -26 deletions)
View changed files
📝
packages/vinext/src/index.ts(+72 -26)➕
tests/og-font-patch.test.ts(+194 -0)📄 Description
Summary
Fixes #642
vinext startcrashes withERR_MODULE_NOT_FOUND: Cannot find package 'a'when the app usesImageResponsefromnext/og. The root cause: thevinext:og-font-patchplugin injects staticimport X from "./X.wasm?module"statements — a workerd-only convention that Node.js can't handle. Node tries to resolve the WASM binary's emscripten import section (module"a") as an npm package.Fix: Replace all static WASM imports with dynamic
import()calls that try the?modulepath (for workerd) and fall back to compiling from bytes (for Node.js). This produces a single build output that runs on both runtimes.new URL()disk-read fallbackHow it works
import("./yoga.wasm?module")succeeds → returns a pre-compiledWebAssembly.Module→ used directlyvinext start): The dynamic import fails →.catch()fires → yoga compiles from inline base64 bytes, resvg reads.wasmfrom disk viareadFileSync+WebAssembly.compileThe key insight is that
import()is lazy — failures are catchable at runtime, unlike staticimportwhich crashes at module parse time.Test plan
tests/og-font-patch.test.ts🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.