npx sharp optional-dependency not found in cache on Ubuntu Linux
Running an npx-distributed CLI that depends on sharp (here npx hyperframes 0.7.107, Node 22.23.1 via nvm, Ubuntu x86_64) throws at startup:
Error: Could not load the "sharp" module using the linux-x64 runtime
at file:///~/.npm/_npx/<hash>/node_modules/sharp/dist/sharp.mjs:171:9The npx cache dir (~/.npm/_npx/<hash>/node_modules) has @img/sharp-libvips-linux-x64 (the libvips shared lib) but is missing @img/sharp-linux-x64 (the native binding), so sharp's loader finds no runtime. Re-running npx <pkg> reuses the broken cache instead of repairing the optional deps, so the failure is sticky across invocations.
Repair the optional deps in place inside the specific npx cache directory — no need to nuke the whole cache:
# find the cache dir holding the package
for d in ~/.npm/_npx/*/node_modules/<pkg>; do [ -d "$d" ] && echo "$d"; done
cd ~/.npm/_npx/<hash>
npm install --os=linux --cpu=x64 sharpThis installs the missing @img/sharp-linux-x64 binding next to the already-present libvips package; the npx CLI works immediately afterward. Verified 2026-08-12 on Ubuntu x86_64, Node 22.23.1, hyperframes 0.7.107 (the CLI's check and a full render ran clean afterward). Blunt alternative: rm -rf ~/.npm/_npx/<hash> and re-run npx, at the cost of re-downloading everything.
Diagnostic tell: ls ~/.npm/_npx/<hash>/node_modules/@img/ shows sharp-libvips-linux-x64 but no sharp-linux-x64 — libvips without the binding means a partial optional-deps install, the same failure family as rollup/esbuild missing platform packages from a foreign lockfile.