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

Sharp module fails to load on linuxmusl-x64 runtime during Next.js build on Fly.io #4236

Open
5 of 11 tasks
ProchaLu opened this issue Oct 15, 2024 · 6 comments
Open
5 of 11 tasks

Comments

@ProchaLu
Copy link

ProchaLu commented Oct 15, 2024

Possible install-time or require-time problem

You must confirm both of these before continuing.

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.

Version 0.33.5

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.

Are you using a supported runtime?

  • I am using Node.js with a version that satisfies ^18.17.0 || ^20.3.0 || >=21.0.0
  • I am using Deno
  • I am using Bun

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

Are you using a supported package manager and installing optional dependencies?

  • I am using npm >= 10.1.0 with --include=optional
  • I am using yarn >= 3.2.0
  • I am using pnpm >= 7.1.0 with --no-optional=false
  • I am using Deno
  • I am using Bun

If you cannot confirm any of these, please upgrade to the latest version of your chosen package manager
and ensure you are allowing the installation of optional or multi-platform dependencies before opening an issue.

What is the complete error message, including the full stack trace?

The error message I encountered during the build process while deploying a Next.js v15.0.0-canary.171 app to Fly.io using Docker is as follows:

./public/images/smiling-cat.webp
Error: Could not load the "sharp" module using the linuxmusl-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 --libc=musl --cpu=x64 sharp
- Consult the installation documentation:
    See https://sharp.pixelplumbing.com/install
    at Object.<anonymous> (/app/node_modules/.pnpm/[email protected]/node_modules/sharp/lib/sharp.js:113:9)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at mod.require (/app/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]_ae2oysp4g4d7aebped4ksyerbi/node_modules/next/dist/server/require-hook.js:65:28)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/app/node_modules/.pnpm/[email protected]/node_modules/sharp/lib/constructor.js:10:1)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)

What is the complete output of running npm install --verbose --foreground-scripts sharp in an empty directory?

1857472c250638:/abc# npm install --verbose --foreground-scripts sharp
npm verbose cli /usr/local/bin/node /usr/local/bin/npm
npm info using [email protected]
npm info using [email protected]
npm verbose title npm install sharp
npm verbose argv "install" "--loglevel" "verbose" "--foreground-scripts" "sharp"
npm verbose logfile logs-max:10 dir:/root/.npm/_logs/2024-10-15T17_17_54_653Z-
npm verbose logfile /root/.npm/_logs/2024-10-15T17_17_54_653Z-debug-0.log
npm http fetch GET 200 https://registry.npmjs.org/sharp 168ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color 57ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/semver 33ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/detect-libc 118ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-wasm32 200ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-arm 650ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-x64 720ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-win32-x64 813ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-darwin-x64 749ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-win32-ia32 441ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-arm64 227ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-s390x 210ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-darwin-arm64 197ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linuxmusl-x64 795ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linuxmusl-arm64 175ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-arm 787ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-x64 694ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-darwin-x64 171ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-arm64 171ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-s390x 671ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-darwin-arm64 818ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linuxmusl-x64 176ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linuxmusl-arm64 878ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@emnapi%2fruntime 1355ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color-convert 38ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color-string 94ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/tslib 31ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color-name 26ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color-name 7ms (cache hit)
npm http fetch GET 200 https://registry.npmjs.org/simple-swizzle 65ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/is-arrayish 68ms (cache miss)
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-win32-x64
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-win32-ia32
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-wasm32
npm verbose reify failed optional dependency /abc/node_modules/@emnapi/runtime
npm verbose reify failed optional dependency /abc/node_modules/tslib
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-linuxmusl-arm64
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-linux-x64
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-linux-s390x
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-linux-arm64
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-linux-arm
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-libvips-linuxmusl-arm64
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-libvips-linux-x64
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-libvips-linux-s390x
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-libvips-linux-arm64
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-libvips-linux-arm
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-libvips-darwin-x64
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-libvips-darwin-arm64
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-darwin-x64
npm verbose reify failed optional dependency /abc/node_modules/@img/sharp-darwin-arm64
npm http fetch GET 200 https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz 139ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color/-/color-4.2.3.tgz 359ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color-string/-/color-string-1.9.1.tgz 384ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz 386ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz 392ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz 389ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz 402ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz 435ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.3.1.tgz 475ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.33.5.tgz 460ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/semver/-/semver-7.6.3.tgz 490ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/sharp/-/sharp-0.33.5.tgz 483ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.0.4.tgz 736ms (cache miss)
npm info run [email protected] install node_modules/sharp node install/check

> [email protected] install
> node install/check

npm info run [email protected] install { code: 0, signal: null }

added 11 packages in 13s

3 packages are looking for funding
  run `npm fund` for details
npm verbose cwd /abc
npm verbose os Linux 5.15.98-fly
npm verbose node v20.18.0
npm verbose npm  v10.8.2
npm verbose exit 0
npm info ok
1857472c250638:/abc#

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

I need to run this command the same Fly.io Docker Linux Alpine env. Will update

Additional Information

After encountering this error, I attempted to redeploy the application an hour later. The error was no longer present, and the deployment worked without any issues. I was not able to reconstruct the error after this.

@lovell
Copy link
Owner

lovell commented Oct 15, 2024

The "Cannot read properties of null (reading 'matches')" error suggests you might be using peer linking - see npm/cli#4367

@ProchaLu
Copy link
Author

@lovell, thx for the fast reply, these logs where from my local machine and not Fly.io. It was a mistake and mixed environments. Right now I try to get the logs from Fly.io.

@ProchaLu
Copy link
Author

Currently, when trying to run the diagnostic commands on Fly.io, the process is being killed due to an out-of-memory issue. I’ve reported this memory issue to the envinfo project. Hopefully, we can find a way to work around the memory limitation and gather the necessary environment information without hitting this problem.

@ProchaLu
Copy link
Author

@lovell, after some research, we found out that envinfo hangs on Linux Alpine, reported in this issue.

npm install --verbose --foreground-scripts sharp ran without issues on Fly.io, and updated the issue.

@lovell
Copy link
Owner

lovell commented Oct 15, 2024

Thanks for the updates, the install log looks good (assuming run on musl-based Linux), I'm not sure what might have caused the original problem.

You're dealing with a multi/cross-platform installation so pnpm is a good choice compared with the current state of npm, especially when lockfiles are involved. Perhaps consider defining custom supportedArchitectures if not already doing so.

If you're able to reproduce and also provide steps for someone else to reproduce then happy to help further.

@lovell
Copy link
Owner

lovell commented Nov 8, 2024

@ProchaLu 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

4 participants
@lovell @ProchaLu and others