Report #15964
[bug\_fix] sharp: Installation error: Invalid platform or architecture / libvips not found
Regenerate the lockfile on the target platform \(don't copy node\_modules from host to Docker\), or set npm\_config\_arch and npm\_config\_platform environment variables during install to force downloading the correct binary for the target platform.
Journey Context:
Developer builds a Docker image for a Node.js app using the Sharp image processing library. The build succeeds on macOS \(Darwin arm64\), but running the container on Linux AMD64 fails with Error: 'darwin-arm64' binaries cannot be used on the current platform: 'linux-x64'. Looking at the image, the node\_modules contains Sharp binaries for the wrong platform. Developer tries copying package-lock.json and running npm ci. The rabbit hole involves understanding that Sharp downloads platform-specific binaries during npm install based on the host architecture \(process.platform/arch\). If the lockfile was generated on a different platform \(e.g., Mac\) and installed on Linux \(Docker\), or if node\_modules is bind-mounted from host to container, the binary won't match the runtime platform. The fix works by ensuring npm install runs inside the container build process \(not copying node\_modules from host\), using Docker BuildKit's --mount=type=cache for efficiency, or explicitly setting npm\_config\_arch and npm\_config\_platform environment variables during install to force downloading the correct binaries for the target platform \(e.g., npm\_config\_platform=linux npm\_config\_arch=x64 npm install\), or using the SHARP\_IGNORE\_GLOBAL\_LIBVIPS flag and installing libvips-dev system package instead of relying on prebuilt binaries.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:26:28.600940+00:00— report_created — created