Repository navigation
Replies: 2 comments 3 replies
|
For cases like this, shouldn’t a project build |
|
Building from source would avoid the check -- but it needs a C++ toolchain, In our case the "project" is Zulip, which builds its help center on self-hosted servers during upgrades from git, so the target is whatever hardware each admin happens to run. We can't reasonably require every admin with an older CPU to build libvips from source, especially for something where the only cost of falling back is slightly larger images. More generally, Sharp is an optional optimization, and Astro already chooses to warn and pass through when Sharp can't handle a given image (withastro/astro#16451). A Sharp that can't load seems like the same flavor of situation. |
Uh oh!
There was an error while loading. Please reload this page.
Body
Summary
When
sharpis installed but its native binary fails to load, have the default image service warn and pass images through unoptimized, instead of failing the build withMissingSharp.Background & Motivation
Sharp's prebuilt Linux x64 binaries require an x86-64-v2 CPU. On older hardware, or on VMs using a generic CPU model like
kvm64orqemu64(common on self-hosted hypervisors),import('sharp')throwsUnsupported CPU: Prebuilt binaries for Linux x64 require v2 microarchitecture. Astro turns this intoMissingSharp: Could not find Sharp, and the build fails. withastro/astro#18432 addresses that misleading error message, by surfacing the "unsupported CPU" part; this proposal is about not failing at all, and instead falling back to providing unoptimized images.For projects that build on the deploying machine, like Zulip's self-hosted help center (built with Starlight), this turns a routine upgrade into a hard failure the administrator can't fix. Several administrators were stuck for months -- one gave up and migrated to a new server (pretty much declaring the old hardware haunted), and others decided to patch
astro.config.mjsby hand on every upgrade.Astro already does this kind of fallback in a nearby case. When Sharp can't decode a particular image, the service warns ("Astro could not optimize image … The image will be used unoptimized") and continues. Extending that to also cover the case of "Sharp can't load at all" seems consistent with it. #16451 pretty much used the argument that "a warning and not crashing seems like a better UX" when there was "no real solution on the user side" which this also fits.
We're working around it in Zulip (zulip/zulip#40415) by trying
import('sharp')in our config and switching topassthroughImageService()if it fails. That works, but ideally this behavior would be handled by Astro itself, instead of in every project that uses it.Goals
sharpisn't installed at all should keep failing loudly. That's usually a dependency mistake worth fixing, not something to hide.Open questions
All reactions