fix(media): make ipx optional to support Cloudflare Workers#404
Merged
larbish merged 3 commits intonuxt-content:mainfrom Apr 8, 2026
Merged
Conversation
ipx depends on sharp which requires native binaries that are unavailable on platforms like Cloudflare Workers, causing builds to fail with `Cannot resolve @img/sharp-wasm32/versions`. - Move ipx from dependencies to optionalDependencies - Use variable-based dynamic import so Rollup/Nitro does not statically follow the import chain into sharp - Gracefully fall back to serving original (unoptimized) images when ipx is unavailable at runtime - Log a build-time warning when ipx is not installed Closes nuxt-content#397
Contributor
|
@CalmProton is attempting to deploy a commit to the NuxtLabs Team on Vercel. A member of the Team first needs to authorize it. |
larbish
approved these changes
Apr 7, 2026
Contributor
larbish
left a comment
There was a problem hiding this comment.
Thanks for the PR! A few changes I made on top:
-
removed
ipxfrom deps (keeping only optionalDependencies), are you sure the graceful install failure on Cloudflare happened with it? optionalDeps still installs automatically on platforms that support sharp -
throw a proper 404 instead of falling with an empty 200 when getOriginalImage returns null
-
removed the createRequire since ipx is still installed by default (and gracefully failing on cloudflare)
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
Contributor
|
Preview works on cloudflare-pages preset! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Builds with the
cloudflare-workerNitro preset fail since v1.5.0 (#397):ipxdepends onsharpwhich requires native binaries that are unavailable on platforms like Cloudflare Workers. Sinceipxwas added as a hard dependency in #369, Rollup resolves the entiresharpdependency tree during bundling and fails.Solution
Make
ipxan optional, gracefully-degrading dependency:package.json— MoveipxfromdependenciestooptionalDependenciesipx.ts— Use a variable-based dynamic import (const id = 'ipx'; await import(id)) so Rollup cannot statically follow the import chain into sharp. Falls back tonullwhen ipx is unavailable.[...path].ts— When ipx is unavailable at runtime, serve original (unoptimized) images via the existinggetOriginalImage()fallback pathmodule.ts— Log a build-time warning whenipxis not installedBehavior
The degraded experience is: the media picker shows full-size images instead of 200×200 thumbnails. Fully functional, slightly more bandwidth.
Testing
NITRO_PRESET=cloudflare-worker npx nuxi build— builds successfully (was failing before)Closes #397