From 0799d13717b50f3e970d65806811836363f01e65 Mon Sep 17 00:00:00 2001 From: mcinquin Date: Mon, 14 Sep 2026 15:12:50 +0200 Subject: [PATCH] fix(sharp): still issue with sharp-wasm --- Dockerfile | 12 ++++++++---- next.config.ts | 8 ++++++++ package-lock.json | 3 +-- package.json | 5 +++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index f18f45f..e9f4079 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,14 +9,14 @@ RUN --mount=type=cache,target=/var/cache/apk \ COPY package.json package-lock.json ./ # sharp prebuilds need x86-64-v2 (SSE4.2+). Hosts like Intel Atom N2800 SIGILL -# in libvips. Install WASM addon explicitly (do NOT use `npm install --cpu=wasm32`, -# which prunes other musl natives e.g. lightningcss) then strip native @img binaries. +# in libvips. Keep @img/sharp-wasm32 (declared dep) and strip native @img binaries +# so sharp cannot load them. Do NOT use `npm install --cpu=wasm32` (prunes lightningcss). RUN --mount=type=cache,target=/root/.npm \ HUSKY=0 npm ci --prefer-offline --no-audit \ - && npm install --no-save --no-audit --no-fund @img/sharp-wasm32@0.35.4 \ && find node_modules/@img -mindepth 1 -maxdepth 1 -type d \( \ -name 'sharp-linux*' -o -name 'sharp-libvips-*' \ - \) -exec rm -rf {} + + \) -exec rm -rf {} + \ + && test -f node_modules/@img/sharp-wasm32/lib/sharp-wasm32-0.35.4.node.wasm # ── Étape 2 : build ─────────────────────────────────────────────────────────── FROM deps AS builder @@ -46,8 +46,12 @@ RUN addgroup --system --gid 1111 hobbyhoops \ COPY --from=builder /app/public ./public COPY --from=builder --chown=hobbyhoops:hobbyhoops /app/.next/standalone ./ COPY --from=builder --chown=hobbyhoops:hobbyhoops /app/.next/static ./.next/static +# Standalone tracing may omit dynamically loaded .wasm; force-copy sharp WASM runtime. +COPY --from=builder --chown=hobbyhoops:hobbyhoops /app/node_modules/@img/sharp-wasm32 ./node_modules/@img/sharp-wasm32 +COPY --from=builder --chown=hobbyhoops:hobbyhoops /app/node_modules/@emnapi ./node_modules/@emnapi RUN mkdir -p /app/data && chown hobbyhoops:hobbyhoops /app/data +RUN test -f /app/node_modules/@img/sharp-wasm32/lib/sharp-wasm32-0.35.4.node.wasm COPY --chmod=755 scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh COPY --chmod=755 scripts/docker-ensure-db.mjs /app/scripts/docker-ensure-db.mjs diff --git a/next.config.ts b/next.config.ts index 0a05bdd..af7cdb3 100644 --- a/next.config.ts +++ b/next.config.ts @@ -8,6 +8,14 @@ const nextConfig: NextConfig = { output: "standalone", poweredByHeader: false, serverExternalPackages: ["better-sqlite3", "sharp"], + // Standalone tracing often omits sharp's dynamically loaded .wasm / natives. + outputFileTracingIncludes: { + "/**": [ + "./node_modules/sharp/**/*", + "./node_modules/@img/sharp-wasm32/**/*", + "./node_modules/@emnapi/**/*", + ], + }, turbopack: { root: projectRoot, }, diff --git a/package-lock.json b/package-lock.json index a04f72c..e750330 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "2.0.1", "dependencies": { "@base-ui/react": "^1.8.0", + "@img/sharp-wasm32": "0.35.4", "@tanstack/react-table": "^9.1.2", "better-sqlite3": "^13.0.3", "class-variance-authority": "^0.7.1", @@ -921,7 +922,6 @@ "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz", "integrity": "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==", "license": "MIT", - "optional": true, "dependencies": { "tslib": "^2.4.0" } @@ -1609,7 +1609,6 @@ "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.35.4.tgz", "integrity": "sha512-zQnl4Kwp7Q6NHsENtU2T/00Zi+w3AQNwz3+UaTyVBy2FpXrzXzGjndpK61onhZjRtRpQXxCTeqw19bVyXOh7jA==", "license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT", - "optional": true, "dependencies": { "@emnapi/runtime": "^1.11.3" }, diff --git a/package.json b/package.json index 48f2d36..1af5aba 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ }, "dependencies": { "@base-ui/react": "^1.8.0", + "@img/sharp-wasm32": "0.35.4", "@tanstack/react-table": "^9.1.2", "better-sqlite3": "^13.0.3", "class-variance-authority": "^0.7.1", @@ -45,10 +46,10 @@ "react-dom": "19.2.8", "recharts": "^3.10.1", "server-only": "^0.0.1", + "sharp": "0.35.4", "tailwind-merge": "^3.6.0", "tw-animate-css": "^1.4.0", - "zod": "^4.5.4", - "sharp": "0.35.4" + "zod": "^4.5.4" }, "devDependencies": { "@commitlint/cli": "^21.2.2",