Error: Could not load the "sharp" module using the linux-x64 runtime — how to fix it
Could not load the "sharp" module using the linux-x64 runtime means sharp found no prebuilt binary for the Linux machine it runs on. Since sharp 0.33 that binary is a separate optional package, @img/sharp-linux-x64, and it goes missing when node_modules was installed on a Mac or Windows and copied over, when the lockfile was made on another platform, or when optional dependencies were skipped. Install on the Linux machine with optional dependencies included, or add the Linux package to the lockfile.
By Livops team, the people who build and run LivopsUpdated
The error, as Node prints it when sharp 0.35 runs on a Linux x64 server without its Linux binary, followed by a stack trace[2]:
Error: Could not load the "sharp" module using the linux-x64 runtime
Possible solutions:
- Ensure optional dependencies can be installed:
npm install --include=optional sharp
- Ensure your package manager supports multi-platform installation:
See https://sharp.pixelplumbing.com/install#cross-platform
- Add platform-specific dependencies:
npm install --os=linux --cpu=x64 sharp
- Consult the installation documentation:
See https://sharp.pixelplumbing.com/install
The runtime in the first line changes with the machine: linuxmusl-x64 on Alpine, linux-arm64 on an ARM server[3]. On Alpine the suggested command gains --libc=musl[2]. sharp 0.32 and older printed different text for the same problem[7]:
Something went wrong installing the "sharp" module
...
- Install for the current linux-x64 runtime: "npm install --platform=linux --arch=x64 sharp"
This page explains how sharp picks its binary, the causes in the order they usually happen, the fix for each, and how to check it before you deploy.
What does the error mean?
sharp’s binary is a separate package per platform
sharp is a native module: it runs compiled sharp and libvips binaries[1]. Since sharp 0.33.0 those prebuilt binaries are distributed through the npm registry and installed by your package manager[6]. sharp lists one optional dependency per platform, such as @img/sharp-linux-x64, @img/sharp-linuxmusl-x64 and @img/sharp-darwin-arm64[4], and each says which system it is for: @img/sharp-linux-x64 is for Linux, x64 and glibc[5]. At install time the package manager picks the binaries for the current operating system and CPU[1], and skips the rest.
What happens when sharp loads
sharp names the machine it runs on: the platform, then musl on a Linux that does not use glibc, then the CPU, as in linux-x64 or linuxmusl-x64[3]. It then tries a binary built from source, the package for that runtime (@img/sharp-linux-x64 for linux-x64), and the WebAssembly package @img/sharp-wasm32; when none of them loads, it throws this error[2]. So in practice the error means node_modules/@img/sharp-linux-x64 is not there. Check on the failing machine:
ls node_modules/@img/
npm ls sharp
Read the Possible solutions lines
sharp chooses the suggestions by what went wrong[2]:
| The error shows | What it means |
|---|---|
Ensure optional dependencies can be installed and Add platform-specific dependencies |
The platform has a prebuilt binary, but its package is missing: causes 1 to 4 below |
Please upgrade Node.js with Found and Requires |
Node is older than sharp supports: cause 5 |
Unsupported CPU: Prebuilt binaries for Linux x64 require v2 microarchitecture |
The CPU is too old for the prebuilt binary: cause 7 |
Update your OS with a glibc or musl version |
The system’s C library is older than the binary needs: cause 7 |
Causes, most common first
1. node_modules was installed on a Mac or Windows and copied to Linux
You ran npm install on a laptop, and the node_modules folder travelled to the server: a Dockerfile that copies the whole project folder, a .zip with node_modules in it, or rsync to a VPS. On the laptop the package manager installed the macOS or Windows binary only[1]; @img/sharp-linux-x64 is for Linux[5], so it was skipped. On the server sharp finds no Linux package and stops[2].
Fix: never ship node_modules; install on the Linux machine. In a Dockerfile, copy package.json and the lockfile, run the install inside the image, and add node_modules to .dockerignore so the laptop’s copy does not overwrite it:
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
2. The lockfile was written on another platform
sharp’s docs warn that a package-lock.json shared by several platforms can cause installation problems, because of npm bug #4828[1]. That issue is about platform-specific optional dependencies left out of package-lock.json when you reinstall with node_modules present[9]. When the Linux package is not in the lockfile, the install on the server has nothing to fetch for Linux. Check:
grep -c '"node_modules/@img/sharp-linux-x64"' package-lock.json
0 means the Linux package is missing. Fix: for npm 10 and later, sharp’s docs add the other platform with the --os, --cpu and --libc flags, and for a Linux target the C library must be named[1]:
# Linux x64 with glibc (Debian, Ubuntu)
npm install --cpu=x64 --os=linux --libc=glibc sharp
# Linux x64 with musl (Alpine)
npm install --cpu=x64 --os=linux --libc=musl sharp
These flags override the operating system, CPU and C library of the native modules npm installs[8]. Commit package-lock.json and run the grep again. With yarn 3 or later, or pnpm 8 or later, sharp’s docs point to their supportedArchitectures setting instead[1].
3. Optional dependencies were skipped
sharp’s binaries are optional dependencies[4], and its docs ask you to make sure the package manager installs them[1]. npm install --omit=optional leaves optional dependencies off the disk, even though they are still resolved into package-lock.json[8]. The older --no-optional flag is a deprecated alias for the same thing[8]. Look for it in the install command, in CI scripts and in .npmrc (omit=optional).
Fix: remove it, or install sharp with optional dependencies included, the first suggestion in the error[2]:
npm install --include=optional sharp
If a dependency type is in both --include and --omit, npm includes it[8].
Next.js. Next.js 16.5.0 lists sharp itself as an optional dependency[11], so --omit=optional drops it too. For next start Next.js strongly recommends sharp, and for output: "standalone" it says you must install it[10]. See Next.js hosting.
4. glibc binaries on Alpine, or musl binaries on Debian
On Alpine, sharp’s runtime is linuxmusl-x64[3], and it needs @img/sharp-linuxmusl-x64[2]. A multi-stage Dockerfile that installs dependencies on a Debian-based image and copies node_modules into an Alpine one carries only the glibc package across, and the error names linuxmusl-x64. Fix: install in the same base image that runs the app, or add both C libraries to the lockfile with the two commands in cause 2. The prebuilt binaries need glibc 2.28 or later, or musl 1.2.5 or later, on x64[1].
5. Node.js is older than sharp needs
sharp 0.35.6 requires Node >=20.9.0[4]; its docs ask for a Node-API v9 runtime such as Node.js 20.9.0 or later[1]. On an older Node the suggestions are replaced by Please upgrade Node.js with the version found and the one required[2][3]. Fix: upgrade Node, for example in .nvmrc. sharp 0.33.0 itself required Node ^18.17.0 or >=20.3.0[6].
6. sharp 0.32 or older: Something went wrong installing
The old message comes from sharp 0.32 and earlier, whose loader looked for one binary inside the package and suggested reinstalling with --platform and --arch[7]. From 0.33.0 the binaries come through the package manager instead[6]. Fix: move to a current sharp, then reinstall on the target machine:
npm install sharp@latest
npm ls sharp
Check sharp’s changelog for breaking changes between your version and the new one.
7. Rare: an old CPU or an old C library
Linux x64 prebuilt binaries need a CPU with SSE4.2, and glibc 2.28 or musl 1.2.5 or later[1]. Below that, the error adds Unsupported CPU: Prebuilt binaries for Linux x64 require v2 microarchitecture, or Update your OS with the C library it found and the one it needs[2]. Fix: a newer machine or base image. Building sharp from source (npm explore sharp -- npm run build) is the other way, and it needs a C++17 compiler and node-gyp[1]; see node-gyp rebuild failed for what that takes.
How to check the fix before you deploy
Install the committed code in a clean Linux container, the way a server would, and load sharp:
git clone . /tmp/sharp-check
docker run --rm -v /tmp/sharp-check:/app -w /app node:22-slim \
sh -c 'npm ci && node -e "import(\"sharp\").then(() => console.log(\"sharp loads\"))"'
sharp loads means the lockfile brings the Linux binary with it. To test Alpine, use node:22-alpine instead. If npm ci itself complains that the lockfile and package.json do not match, see npm ci: lockfile out of sync.
On Livops
- An uploaded folder never brings node_modules. When you upload a folder or a
.zip,node_modulesis dropped automatically, and Livops installs the dependencies itself. So cause 1 cannot come from an upload; see Ways to deploy. - Commit the lockfile with Linux in it. For a GitHub project, run the
grepfrom cause 2 and commitpackage-lock.jsononce it lists the Linux package. - Check the install command. Livops detects the framework and picks the install command; you can change it under Settings → Install, or with
installinlivops.json, which is applied on every deploy. Keep--omit=optionaland--no-optionalout of it;npm ci --include=optionalis fine. See Frameworks and livops.json. - Node 22 or 24. Those are the Node versions Livops has, and both are newer than sharp’s minimum, so cause 5 does not apply unless you pinned an older sharp. Livops reads
.nvmrcand.node-version. - Your own Dockerfile. If the repository has a
Dockerfile, it is used, and causes 1 and 4 then come from what it copies and which base image it uses. - Where the error shows. If the build step loads sharp, the deploy fails as
build_failedwith the error in the build log, and the assistant explains it. If the app loads sharp when it starts, the deploy fails asstart_failed, with the error on the Logs page; see The app did not start. If it loads sharp only when it first handles an image, the deploy itself can succeed, and the error appears on the Logs page when that first image request comes in;livops logs <service> -ffollows it from the terminal.
A Node app costs 39 credits a month (39,000 so’m); see Pricing.
If the install stops earlier, on a native addon that compiles, see node-gyp rebuild failed; if Node cannot find a module at all, see Cannot find module.
Questions
What does Could not load the sharp module using the linux-x64 runtime mean?
sharp runs on Linux with an x64 CPU and glibc, and it could not load a binary for that platform. Since sharp 0.33 that binary comes in a separate optional package, @img/sharp-linux-x64, which the package manager installs only on a matching machine. The error almost always means that package is not in node_modules.
Why does sharp work on my Mac but not on the server?
On a Mac the package manager installed the macOS binary, such as @img/sharp-darwin-arm64, and nothing for Linux. If that node_modules folder is copied to a Linux server, or the lockfile was written without the Linux packages, the server has no binary it can load. Install the dependencies on the server itself.
How do I add the Linux binary to package-lock.json from a Mac?
sharp's installation docs give npm install --cpu=x64 --os=linux --libc=glibc sharp for Debian-style Linux and the same with --libc=musl for Alpine. When the target is Linux the C library must be named. Commit the lockfile, then check that it lists node_modules/@img/sharp-linux-x64.
Does npm install --omit=optional break sharp?
Yes. sharp ships its binaries as optional dependencies, and --omit=optional, or the older --no-optional, leaves them out of node_modules even though the lockfile still lists them. sharp's docs ask that the package manager installs optional dependencies, and the error itself suggests npm install --include=optional sharp.
What is the linuxmusl-x64 runtime?
It is Linux on x64 with the musl C library, as on Alpine. sharp names its runtime by platform, C library and CPU, so on Alpine the error says linuxmusl-x64 and needs the @img/sharp-linuxmusl-x64 package. A node_modules installed on a glibc system such as Debian does not have it.
What about Something went wrong installing the sharp module?
That is the same problem in sharp 0.32 and older, which used a different loader and error text. From 0.33.0 the prebuilt binaries come from the npm registry through the package manager. Upgrading to a current sharp and installing on the target machine is the usual fix.
Sources
- sharp — Installation (sharp.pixelplumbing.com). Checked .
- sharp v0.35.6 source — lib/sharp.mjs (github.com). Checked .
- sharp v0.35.6 source — lib/libvips.mjs (github.com). Checked .
- sharp v0.35.6 source — package.json (github.com). Checked .
- sharp v0.35.6 source — npm/linux-x64/package.json (@img/sharp-linux-x64) (github.com). Checked .
- sharp — Changelog v0.33.0 (sharp.pixelplumbing.com). Checked .
- sharp v0.32.6 source — lib/sharp.js (github.com). Checked .
- npm Docs — config (omit, include, optional, os, cpu, libc) (docs.npmjs.com). Checked .
- npm/cli issue 4828 — platform-specific optional dependencies not included in package-lock.json (github.com). Checked .
- Next.js Docs — Sharp Missing In Production (nextjs.org). Checked .
- Next.js v16.5.0 source — packages/next/package.json (github.com). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your Node appRelated
- gyp ERR! build error / gyp ERR! find Python: node-gyp rebuild failed during npm install, how to fix itgyp ERR! build error, gyp ERR! find Python or gyp ERR! stack Error: not found: make means npm install tried to compile a native addon such as bcrypt, sqlite3 or sharp, and the machine has no Python, make or C++ compiler. It usually happens because no prebuilt binary fits your Node version or platform (Alpine/musl included). Upgrade to a release with prebuilt binaries, switch to a pure-JavaScript package such as bcryptjs, or install the build tools.
- npm ci can only install packages when your package.json and package-lock.json are in sync: how to fix itnpm ci can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync (npm error code EUSAGE) means the committed lockfile no longer matches package.json: a dependency was added or changed without re-running npm install, or the lockfile was not committed. Run npm install locally, commit package.json and package-lock.json together, and npm ci passes.
- Error: Cannot find module (MODULE_NOT_FOUND) in Node.js: how to fix itError: Cannot find module 'x' with code MODULE_NOT_FOUND, or ERR_MODULE_NOT_FOUND with import, means Node.js looked for a package or file and it was not there. On a server the usual causes are a package missing from package.json, a devDependency the install skipped, a path whose case differs from the file, a start command pointing at a file that was never built, or an ES module import without its .js extension.
- npm failed with return code 1 (npm ERR! code 1): how to fix the buildnpm failed with return code 1, or npm install exited with 1, is npm ERR! code 1 in newer npm: it only says that a script npm ran exited with code 1. The real error is printed above it: usually a compile or type error, a lockfile out of sync with package.json, or a dependency whose install script failed. Find the first error line above code 1, fix that, and the build passes.
- exec format error in Docker: the image was built for another CPUThe kernel refused to run the container's program because it is not an executable for this machine: almost always a binary or image built for arm64 (an Apple Silicon Mac) running on an amd64 server, or the reverse. Build for the server's platform with --platform linux/amd64, or as a multi-platform image; if the file is a script, give it a #! line.
- Next.js hosting without Vercel: the options comparedNext.js runs on any host that runs Node: next build, then next start, and every feature works, Server Actions and image optimization included. On Livops a repository with next in package.json runs as a server from a push for 39 credits a month (39,000 so'm), and a static export is free. Here is how Vercel, Render, Railway, Fly.io and a VPS compare.
- Node.js hosting in 2026: how to deploy an Express appA Node.js server in production needs one long-running process that listens on the port it is given, restarts when it crashes and exits cleanly on SIGTERM. On Livops you push a repository with package.json and it runs as a web app for 39 credits a month (39,000 so'm). Here is what Node needs, and how a VPS, Render, Railway, Fly.io, DigitalOcean and Heroku compare.
- bcrypt_lib.node: invalid ELF header — why bcrypt fails in Docker and on Linuxinvalid ELF header, with code ERR_DLOPEN_FAILED, means Node on Linux tried to load a bcrypt binary that is not a Linux library: node_modules was installed on a Mac or Windows and then copied to the server, by a COPY . . without a .dockerignore or a committed node_modules folder. Keep node_modules out of the image and the repository and install inside Linux with npm ci, or switch to bcryptjs, which has no binary at all.