Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[email protected] fails to compile with NextJS 15 (works with [email protected]) #4361

Open
5 tasks done
JonBernardHealia opened this issue Apr 4, 2025 · 10 comments
Open
5 tasks done

Comments

@JonBernardHealia
Copy link

JonBernardHealia commented Apr 4, 2025

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
@lovell
Copy link
Owner

lovell commented Apr 4, 2025

There's a lot going on here. Please can you simplify/reduce the steps required to reproduce this, perhaps as a standalone repo, and without a dependency on third party services.

@nemanjam
Copy link

nemanjam commented Apr 6, 2025

Astro, same thing locally on Ubuntu.

@maiconsanson
Copy link

maiconsanson commented Apr 6, 2025

Same here, but only in production.
After the upgrade, the Vercel build fails with Error: Command "pnpm install" exited with 1.

Related:

@lovell
Copy link
Owner

lovell commented Apr 6, 2025

Please can someone produce a complete, minimal, standalone repo that allows someone else to reproduce.

@perepechin
Copy link

perepechin commented Apr 8, 2025

After upgrading to 0.34.1 build fails with this error in WP Engine:
Error: Could not load the "sharp" module using the linux-x64 runtime

I can build locally without any issues on my Windows machine.

To make it work in WP Engine, I downgraded sharp to 0.33.5 version.

@lovell
Copy link
Owner

lovell commented Apr 8, 2025

Clear, simple steps for someone else to reproduce is the only thing that's going to help here.

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)

If you see the mention of libvips-cpp.so.42 (and exactly that version) in your error message then you are using v0.33.x rather than v0.34.x.

@nemanjam
Copy link

Some global OS package is missing in Ubuntu 24.04 desktop, in the next few days I will see which one exactly. It works in more complete Linux images.

@maiconsanson
Copy link

Vercel fixed it.: vercel/next.js#77839

@omavi
Copy link

omavi commented Apr 11, 2025

I'm using npm. In addition to updating to next 15.3.0 and sharp 0.34.1, I needed to regenerate my package-lock.json. The following did the trick for me: rm -rf node_modules package-lock.json && npm install

@lovell
Copy link
Owner

lovell commented Apr 11, 2025

@JonBernardHealia As creator of this issue, were you able to make any progress with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants