Auto-detect WASM fallback for unsupported platforms (Termux/Android)
Author: kore4lyfCreated Jun 30, 2026Updated Sep 27, 2026
Labelsquestion
Problem
Sharp v0.35.2 fails to load on Termux (Android ARM64):
Error: Could not load the "sharp" module using the android-arm64 runtimeNo prebuilt binaries exist for android-arm64v8.
Workaround (verified working)
npm install @img/sharp-wasm32Proposed Solution
Auto-detect unsupported platforms and fall back to WASM:
if (loadError && !process.env.SHARP_IGNORE_WASM_FALLBACK) {
try {
module.exports = require('@img/sharp-wasm32');
return;
} catch (_wasmError) {}
}Benefits
- Zero-config for unsupported platforms
- WASM is slower but functional
- Opt-out via
SHARP_IGNORE_WASM_FALLBACK=1
Related
- #3850, #4324, #4161
Source: lovell/sharp