You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dev: client optimizeDeps excludes serverExternalPackages, which breaks optional requires in client deps (linkedom → canvas) #3484
vinext 1.0.0-beta.12 (also on main at c4b705e), App Router, Vite 8.3.1.
The client environment's optimizeDeps.exclude includes the whole default serverExternalPackages list (packages/vinext/src/index.ts, the client environment in the App Router config). canvas is on that list. A client dependency that requires canvas optionally, inside a try/catch, then breaks in vinext dev:
With canvas excluded, the dep optimizer treats it as external and hoists the require into a top-level import * as m from "canvas" in .vite/deps/linkedom.js. Vite resolves that import to __vite-optional-peer-dep:canvas:linkedom, which throws on evaluation, outside the try. Any client module that imports linkedom fails to load:
Error: Could not resolve "canvas" imported by "linkedom".
at http://localhost:5174/@id/__vite-optional-peer-dep:canvas:linkedom:2:7
Plain Vite (no exclusion) bundles the optional peer dep inside the try, and the shim is used. vinext build is not affected.
Repro: an App Router client component that does import("linkedom") in the browser, canvas not installed, vinext dev.
Workaround: a plugin whose configEnvironment hook removes canvas from the client environment's optimizeDeps.exclude.
Suggested fix: exclude server-external packages from the client optimizer only when they are imported directly from app code, or do not apply the list to packages that are reached only through a dependency's require.
Activity
james-elicx commentedon Sep 29, 2026
I submitted vitejs/vite#23600 to Vite which should fix this, so just pending new Vite releases.