build(uploads): add sharp for image re-encoding (#226)

Verified where it actually has to run rather than only here: the production image builds and `require('sharp')` succeeds inside it on Node v20.20.2, linux/x64, with libvips 8.18.6 and `withExif` available, needing no build toolchain. The architecture question is already settled by this same node:20-bookworm-slim base running in production today, and sharp ships glibc prebuilds for both linux-x64 and linux-arm64, so it adds no constraint that deployment did not already satisfy.

Installing it locally found a trap worth recording. sharp requires Node >=20.9.0 and its platform binary is an *optional* dependency, so npm skips it when the engine check fails and still reports success. Installed under this machine's default 18.16.1 the result is a node_modules that looks complete and throws `Could not load the "sharp" module using the win32-x64 runtime` at require time — which reads as a broken package rather than as a wrong Node version. The fix is `npm install --include=optional sharp` under Node 20+, and the prevention is using start-local.ps1 or run-tests.ps1, which switch first.

`engines` is now declared so npm at least warns, and the README's existing Node 20 section says what the failure looks like, since the error message names a runtime rather than a version and points nowhere useful.

The lockfile carries every platform variant including linux-x64 and linux-arm64, so a build on another platform resolves correctly. The Dockerfile does not copy the lockfile at all and installs fresh, so this matters for contributors rather than for the image.

Ref #226
This commit is contained in:
2026-08-29 10:45:01 -05:00
parent 5a3c0db0bc
commit 7d45b69305
3 changed files with 565 additions and 2 deletions
+5 -1
View File
@@ -3,6 +3,9 @@
"version": "1.0.0",
"private": true,
"main": "dist/server.js",
"engines": {
"node": ">=20.9.0"
},
"scripts": {
"build": "tsc",
"lint": "eslint src scripts",
@@ -33,7 +36,8 @@
"node-cron": "^3.0.3",
"node-pg-migrate": "^7.6.1",
"nodemailer": "^6.9.14",
"pg": "^8.12.0"
"pg": "^8.12.0",
"sharp": "^0.35.4"
},
"devDependencies": {
"@eslint/js": "^9.39.5",