[GH-ISSUE #3167] [Issue]: Sprite generation unavailable on Termux — TERMUX_FORCE_INSTALL never actually forces pnpm to install @img/sharp-wasm32 #1699

Closed
opened 2026-10-21 05:41:49 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @Magiwarriorx on GitHub (Jul 3, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3167

Originally assigned to: @SpicyMarinara on GitHub.

Summary

On Termux/Android, sprite generation (and all other sharp-backed image processing) is unavailable because sharp has zero platform binaries installed — not the native @img/sharp-linux-arm64 (correctly filtered out; see below) and, more importantly, not the @img/sharp-wasm32 fallback the setup is supposed to rely on. Root cause: start-termux.sh writes supportedArchitectures.cpu[]=wasm32 into .npmrc and sets TERMUX_FORCE_INSTALL=1, but the "force" path only runs a plain pnpm install, which no-ops against an already-satisfied lockfile and never re-links the newly-allowed optional dependency.

Expected behavior

On Termux, after start-termux.sh adds the wasm32 architecture to .npmrc, pnpm should install @img/sharp-wasm32, sharp should load via its built-in wasm fallback, and sprite generation / background cleanup should work.

Actual behavior

sharp fails to load entirely. GET /api/sprites/capabilities reports spriteGenerationAvailable: false, and the sprite generation UI is disabled. On disk, node_modules/.pnpm contains only sharp@0.34.5 and @img/colour (a pure-JS helper) — no @img/sharp-* binary package at all.

Because packages/server/src/routes/sprites.routes.ts swallows the module-load error with a bare catch {} (around line 35), the underlying reason is invisible in logs, which is why this has been hard to pin down.

Steps to reproduce

  1. Install/run Marinara Engine on Termux (Android arm64) via start-termux.sh.
  2. Confirm .npmrc contains supportedArchitectures.cpu[]=wasm32 (the script adds it).
  3. Check the store: ls node_modules/.pnpm | grep -i "img+sharp" → nothing.
  4. Try to load sharp directly:
    cd packages/server
    node --input-type=module -e "import('sharp').then(()=>console.log('LOADED')).catch(e=>console.error('FAILED:',e.message))"
    
    → fails, because no @img/sharp-* binary is present.
  5. Sprite generation is disabled in the UI / capabilities endpoint.

Environment

  • Marinara Engine version: 2.0.9
  • Install type: termux
  • OS + version: Android (arm64), Termux, Node 24, bionic libc
  • Browser or app shell: Android WebView shell (also reproduces in a plain browser against the Termux server)

Logs, screenshots, or video

Diagnosis captured on a real device:

  • .npmrc does contain supportedArchitectures.cpu[]=wasm32 (flag present).
  • npm view @img/sharp-wasm32@0.34.5 os cpu libc → only wasm32 (i.e. cpu: wasm32, no os or libc constraint), so the package is installable wherever wasm32 is an allowed CPU.
  • Store contains only sharp@0.34.5 + @img/colour@1.1.0; no @img/sharp-* binary.
  • A plain forced reinstall (corepack pnpm@<ver> install) throws no error and changes nothing — the classic "Already up to date" no-op.
  • Running the install with --force finally pulls @img/sharp-wasm32@0.34.5, after which the direct load test above prints LOADED and sprite generation works.

Additional context

Why the native binary is (correctly) absent. Termux runs on Android's bionic libc, not glibc/musl. @img/sharp-linux-arm64 is gated libc: glibc, so pnpm rightly filters it out — it would not run on bionic. This is why the whole Termux path depends on the @img/sharp-wasm32 build; there is no native path on Termux.

The actual bug is in start-termux.sh. The force path:

if [ ! -d "node_modules" ] || [ "$TERMUX_FORCE_INSTALL" = "1" ]; then
    echo "  [..] Installing dependencies${TERMUX_FORCE_INSTALL:+ (refreshing for platform fix)}..."
    run_pnpm install
fi

The comment where the flag is set (near line 64) says "Force pnpm to re-resolve optional deps on next install," but run_pnpm install does not force anything. When node_modules already exists and the lockfile is satisfied, pnpm treats the install as up-to-date and never re-links the newly-permitted @img/sharp-wasm32. So the .npmrc edit and the actual install drift out of sync: the flag is written, but the packages it should pull in are never installed.

Verified fix (on-device). Making the forced install actually force re-resolution installs @img/sharp-wasm32 and restores sprite generation. Simplest change: use run_pnpm install --force on the TERMUX_FORCE_INSTALL path (a more surgical alternative is to remove the stale node_modules/.pnpm/sharp* / @img entries before installing so only the sharp subtree is refetched).

Suggested follow-ups (separate, smaller changes):

  1. Surface the real error instead of the bare catch {} in sprites.routes.ts (log the aggregated sharp load error at debug/warn). sharp reports every failed candidate path, which makes "wasm package missing" vs. "wasm ran out of memory" vs. "compile blocked" diagnosable at a glance — this alone would have made the current bug obvious.
  2. Consider making the @img/sharp-wasm32 fallback more robust than a Termux-only, script-order-dependent .npmrc opt-in (e.g. also verify the package is present after install and re-run with --force if not), so a user who installs outside the exact start-termux.sh path isn't left with a non-functional sharp.

Notes:

  • sharp is already an optionalDependency and every call site lazy-loads it, so the server still boots without it — this is specifically about restoring functionality on Termux, not about crashes.
  • The pure-JS codec swap discussed elsewhere (replacing sharp's decode/encode/resize/crop with a dependency-free implementation) remains a viable Plan B if the wasm fallback proves unreliable on lower-end devices, but is out of scope for this bug — the wasm fallback works once it is actually installed.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Magiwarriorx on GitHub (Jul 3, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3167 Originally assigned to: @SpicyMarinara on GitHub. ## Summary On Termux/Android, sprite generation (and all other `sharp`-backed image processing) is unavailable because `sharp` has **zero** platform binaries installed — not the native `@img/sharp-linux-arm64` (correctly filtered out; see below) and, more importantly, not the `@img/sharp-wasm32` fallback the setup is supposed to rely on. Root cause: `start-termux.sh` writes `supportedArchitectures.cpu[]=wasm32` into `.npmrc` and sets `TERMUX_FORCE_INSTALL=1`, but the "force" path only runs a plain `pnpm install`, which no-ops against an already-satisfied lockfile and never re-links the newly-allowed optional dependency. ## Expected behavior On Termux, after `start-termux.sh` adds the wasm32 architecture to `.npmrc`, `pnpm` should install `@img/sharp-wasm32`, `sharp` should load via its built-in wasm fallback, and sprite generation / background cleanup should work. ## Actual behavior `sharp` fails to load entirely. `GET /api/sprites/capabilities` reports `spriteGenerationAvailable: false`, and the sprite generation UI is disabled. On disk, `node_modules/.pnpm` contains only `sharp@0.34.5` and `@img/colour` (a pure-JS helper) — **no** `@img/sharp-*` binary package at all. Because `packages/server/src/routes/sprites.routes.ts` swallows the module-load error with a bare `catch {}` (around line 35), the underlying reason is invisible in logs, which is why this has been hard to pin down. ## Steps to reproduce 1. Install/run Marinara Engine on Termux (Android arm64) via `start-termux.sh`. 2. Confirm `.npmrc` contains `supportedArchitectures.cpu[]=wasm32` (the script adds it). 3. Check the store: `ls node_modules/.pnpm | grep -i "img+sharp"` → nothing. 4. Try to load sharp directly: ```bash cd packages/server node --input-type=module -e "import('sharp').then(()=>console.log('LOADED')).catch(e=>console.error('FAILED:',e.message))" ``` → fails, because no `@img/sharp-*` binary is present. 5. Sprite generation is disabled in the UI / capabilities endpoint. ## Environment - Marinara Engine version: 2.0.9 - Install type: termux - OS + version: Android (arm64), Termux, Node 24, bionic libc - Browser or app shell: Android WebView shell (also reproduces in a plain browser against the Termux server) ## Logs, screenshots, or video Diagnosis captured on a real device: - `.npmrc` **does** contain `supportedArchitectures.cpu[]=wasm32` (flag present). - `npm view @img/sharp-wasm32@0.34.5 os cpu libc` → only `wasm32` (i.e. `cpu: wasm32`, **no** `os` or `libc` constraint), so the package is installable wherever wasm32 is an allowed CPU. - Store contains only `sharp@0.34.5` + `@img/colour@1.1.0`; no `@img/sharp-*` binary. - A plain forced reinstall (`corepack pnpm@<ver> install`) throws no error and changes nothing — the classic "Already up to date" no-op. - Running the install **with `--force`** finally pulls `@img/sharp-wasm32@0.34.5`, after which the direct load test above prints `LOADED` and sprite generation works. ## Additional context **Why the native binary is (correctly) absent.** Termux runs on Android's **bionic** libc, not glibc/musl. `@img/sharp-linux-arm64` is gated `libc: glibc`, so pnpm rightly filters it out — it would not run on bionic. This is why the whole Termux path depends on the `@img/sharp-wasm32` build; there is no native path on Termux. **The actual bug is in `start-termux.sh`.** The force path: ```sh if [ ! -d "node_modules" ] || [ "$TERMUX_FORCE_INSTALL" = "1" ]; then echo " [..] Installing dependencies${TERMUX_FORCE_INSTALL:+ (refreshing for platform fix)}..." run_pnpm install fi ``` The comment where the flag is set (near line 64) says "Force pnpm to re-resolve optional deps on next install," but `run_pnpm install` does not force anything. When `node_modules` already exists and the lockfile is satisfied, pnpm treats the install as up-to-date and never re-links the newly-permitted `@img/sharp-wasm32`. So the `.npmrc` edit and the actual install drift out of sync: the flag is written, but the packages it should pull in are never installed. **Verified fix (on-device).** Making the forced install actually force re-resolution installs `@img/sharp-wasm32` and restores sprite generation. Simplest change: use `run_pnpm install --force` on the `TERMUX_FORCE_INSTALL` path (a more surgical alternative is to remove the stale `node_modules/.pnpm/sharp*` / `@img` entries before installing so only the sharp subtree is refetched). **Suggested follow-ups (separate, smaller changes):** 1. Surface the real error instead of the bare `catch {}` in `sprites.routes.ts` (log the aggregated sharp load error at `debug`/`warn`). sharp reports every failed candidate path, which makes "wasm package missing" vs. "wasm ran out of memory" vs. "compile blocked" diagnosable at a glance — this alone would have made the current bug obvious. 2. Consider making the `@img/sharp-wasm32` fallback more robust than a Termux-only, script-order-dependent `.npmrc` opt-in (e.g. also verify the package is present after install and re-run with `--force` if not), so a user who installs outside the exact `start-termux.sh` path isn't left with a non-functional `sharp`. Notes: - `sharp` is already an `optionalDependency` and every call site lazy-loads it, so the server still boots without it — this is specifically about restoring functionality on Termux, not about crashes. - The pure-JS codec swap discussed elsewhere (replacing sharp's decode/encode/resize/crop with a dependency-free implementation) remains a viable Plan B if the wasm fallback proves unreliable on lower-end devices, but is out of scope for this bug — the wasm fallback works once it is actually installed. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:41:49 +07:00
Author
Owner

@Magiwarriorx commented on GitHub (Jul 3, 2026):

Happy to PR this myself but wanted to respect CONTRIBUTING.md.

Fix tested and working on my S26 Ultra.

<!-- gh-comment-id:4872774726 --> @Magiwarriorx commented on GitHub (Jul 3, 2026): Happy to PR this myself but wanted to respect CONTRIBUTING.md. Fix tested and working on my S26 Ultra.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 3, 2026):

Codex is taking this issue in branch codex/fix-termux-sharp-wasm-install, targeting staging.

<!-- gh-comment-id:4874309465 --> @SpicyMarinara commented on GitHub (Jul 3, 2026): Codex is taking this issue in branch `codex/fix-termux-sharp-wasm-install`, targeting `staging`.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 3, 2026):

Opened draft PR #3168 with the Termux forced-install fix and sharp-load diagnostic logging: https://github.com/Pasta-Devs/Marinara-Engine/pull/3168

<!-- gh-comment-id:4874362319 --> @SpicyMarinara commented on GitHub (Jul 3, 2026): Opened draft PR #3168 with the Termux forced-install fix and sharp-load diagnostic logging: https://github.com/Pasta-Devs/Marinara-Engine/pull/3168
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1699
No description provided.