Skip to content

Sharp@0.34.0 fails to compile with NextJS 15 (works with sharp@0.33.5) #4361

Description

@JonBernardHealia

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

  • Running npm install sharp completes without error.
  • Running node -e "require('sharp')" completes without error.

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

  • I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

Does this problem relate to file caching?

The default behaviour of libvips is to cache input files, which can lead to EBUSY or EPERM errors on Windows.
Use sharp.cache(false) to switch this feature off.

  • Adding sharp.cache(false) does not fix this problem.

Does this problem relate to images appearing to have been rotated by 90 degrees?

Images that contain EXIF Orientation metadata are not auto-oriented. By default, EXIF metadata is removed.

  • To auto-orient pixel values use the parameter-less rotate() operation.

  • To retain EXIF Orientation use keepExif().

  • Using rotate() or keepExif() does not fix this problem.

What are the steps to reproduce?

  • Upgrade sharp to 0.34.0
  • Have a next 15.2.3 app
  • have a docker build
  • run in github actions

What is the expected behaviour?

  • Docker image builds

Docker build logs

#20 [builder 6/7] RUN yarn build
#20 0.384 yarn run v1.22.22
#20 0.428 $ next build
#20 1.261    ▲ Next.js 15.2.3
#20 1.262 
#20 1.345    Creating an optimized production build ...
#20 125.5 Failed to compile.
#20 125.5 
#20 125.5 ./public/images/logo.png
#20 125.5 Error: Could not load the "sharp" module using the linuxmusl-x64 runtime
#20 125.5 ERR_DLOPEN_FAILED: Error loading shared library libvips-cpp.so.42: No such file or directory (needed by /app/node_modules/next/node_modules/@img/sharp-linuxmusl-x64/lib/sharp-linuxmusl-x64.node)
#20 125.5 Possible solutions:
#20 125.5 - Ensure optional dependencies can be installed:
#20 125.5     npm install --include=optional sharp
#20 125.5 - Ensure your package manager supports multi-platform installation:
#20 125.5     See https://sharp.pixelplumbing.com/install#cross-platform
#20 125.5 - Add platform-specific dependencies:
#20 125.5     npm install --os=linux --libc=musl --cpu=x64 sharp
#20 125.5 - Consult the installation documentation:
#20 125.5     See https://sharp.pixelplumbing.com/install
#20 125.5     at Object.<anonymous> (/app/node_modules/next/node_modules/sharp/lib/sharp.js:113:9)
#20 125.5     at Module._compile (node:internal/modules/cjs/loader:1529:14)
#20 125.5     at Module._extensions..js (node:internal/modules/cjs/loader:1613:10)
#20 125.5     at Module.load (node:internal/modules/cjs/loader:1275:32)
#20 125.5     at Module._load (node:internal/modules/cjs/loader:1096:12)
#20 125.5     at Module.require (node:internal/modules/cjs/loader:1298:19)
#20 125.5     at mod.require (/app/node_modules/next/dist/server/require-hook.js:65:28)
#20 125.5     at require (node:internal/modules/helpers:182:18)
#20 125.5     at Object.<anonymous> (/app/node_modules/next/node_modules/sharp/lib/constructor.js:10:1)
#20 125.5     at Module._compile (node:internal/modules/cjs/loader:1529:14)

Partial Dockerfile

FROM base AS deps
WORKDIR /app
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
  if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
  elif [ -f package-lock.json ]; then npm ci; \
  elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
  else echo "Lockfile not found." && exit 1; \
  fi
RUN yarn add sharp

FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

ENV NEXT_TELEMETRY_DISABLED 1

RUN npx prisma generate
RUN yarn build

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions