lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.33k stars 1.3k forks source link

Bun + Alpine Linux: error: Could not load the "sharp" module using the linux-x64 runtime - in github actions #4215

Closed rohit-nayak123 closed 2 months ago

rohit-nayak123 commented 2 months ago

I am just trying to automatic the process of deployment in Azure app service by pushing the code to GitHub and creating a docker image from it and pushing it to docker hub using GitHub actions. Well, everything was working just fine until the latest update of Bun js., everything is fine in local but in productions with latest updates it is not.

link to my GitHub repo.

GitHub is able to create a docker image but when it is runed after finest it is showing error:

334 |     jxlLossless: false,
335 |     rawDepth: 'uchar',
336 |     tileSize: 256,
337 |     tileOverlap: 0,
338 |     tileContainer: 'fs',
339 |     tileLayout: 'dz',
                      ^
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
      at node_modules/sharp/lib/constructor.js:339:17
      at /$bunfs/root/compressapp.exe:2:348
      at node_modules/sharp/lib/constructor.js:365:8
      at /$bunfs/root/compressapp.exe:2:348
      at node_modules/combined-stream/lib/combined_stream.js:118:37
      at /$bunfs/root/compressapp.exe:2:348
      at index.ts:9:1

Bun v1.1.28-canary.15+036e03034 (Linux x64 baseline)

Possible install-time or require-time problem

You must confirm both of these before continuing.

Are you using the latest version of sharp?

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?

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?

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?

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

#8 [ 5/10] RUN bun install --verbose --foreground-scripts sharp #8 0.123 bun add v1.1.28-canary.4 (a0939ca4) #8 0.127 Loaded 316 hoisted_dependencies #8 0.127 Loaded 398 resolutions #8 0.127 Loaded 398 dependencies #8 0.127 Loaded 8 extern_strings #8 0.127 Loaded 21274 string_bytes #8 0.145 Clean lockfile: 297 packages - 297 packages in 865.7us #8 0.153 #8 0.153 -- BEGIN SHA512/256(`${alphabetize(name)}@${order(version)}`) -- #8 0.153 @emnapi/runtime@1.2.0 #8 0.153 @hono/zod-validator@0.2.2 #8 0.153 @img/sharp-darwin-arm64@0.33.5 #8 0.153 @img/sharp-darwin-x64@0.33.5 #8 0.153 @img/sharp-libvips-darwin-arm64@1.0.4 #8 0.153 @img/sharp-libvips-darwin-x64@1.0.4 #8 0.153 @img/sharp-libvips-linux-arm@1.0.5 #8 0.153 @img/sharp-libvips-linux-arm64@1.0.4 #8 0.153 @img/sharp-libvips-linux-s390x@1.0.4 #8 0.153 @img/sharp-libvips-linux-x64@1.0.4 #8 0.153 @img/sharp-libvips-linuxmusl-arm64@1.0.4 #8 0.153 @img/sharp-libvips-linuxmusl-x64@1.0.4 #8 0.153 @img/sharp-linux-arm@0.33.5 #8 0.153 @img/sharp-linux-arm64@0.33.5 #8 0.153 @img/sharp-linux-s390x@0.33.5 #8 0.153 @img/sharp-linux-x64@0.33.5 #8 0.153 @img/sharp-linuxmusl-arm64@0.33.5 #8 0.153 @img/sharp-linuxmusl-x64@0.33.5 #8 0.153 @img/sharp-wasm32@0.33.5 #8 0.153 @img/sharp-win32-ia32@0.33.5 #8 0.153 @img/sharp-win32-x64@0.33.5 #8 0.153 @nodelib/fs.scandir@2.1.5 #8 0.153 @nodelib/fs.stat@2.0.5 #8 0.153 @nodelib/fs.walk@1.2.8 #8 0.153 @oven/bun-linux-x64@1.1.27 #8 0.153 @sec-ant/readable-stream@0.4.1 #8 0.153 @sindresorhus/is@0.7.0 #8 0.153 @sindresorhus/is@6.3.1 #8 0.153 @sindresorhus/merge-streams@2.3.0 #8 0.153 @tokenizer/token@0.3.0 #8 0.153 @trysound/sax@0.2.0 #8 0.153 @types/imagemin@9.0.0 #8 0.153 @types/imagemin-gifsicle@7.0.4 #8 0.153 @types/imagemin-svgo@10.0.5 #8 0.153 @types/node@20.12.14 #8 0.153 @types/node@22.5.4 #8 0.153 @types/svgo@2.6.4 #8 0.153 @types/ws@8.5.12 #8 0.153 arch@2.2.0 #8 0.153 archive-type@4.0.0 #8 0.153 asynckit@0.4.0 #8 0.153 axios@1.7.7 #8 0.153 base64-js@1.5.1 #8 0.153 bin-build@3.0.0 #8 0.153 bin-check@4.1.0 #8 0.153 bin-version@3.1.0 #8 0.153 bin-version-check@4.0.0 #8 0.153 bin-wrapper@4.1.0 #8 0.153 bl@1.2.3 #8 0.153 boolbase@1.0.0 #8 0.153 braces@3.0.3 #8 0.153 buffer@5.7.1 #8 0.153 buffer-alloc@1.2.0 #8 0.153 buffer-alloc-unsafe@1.1.0 #8 0.153 buffer-crc32@0.2.13 #8 0.153 buffer-fill@1.0.0 #8 0.153 bun-types@1.1.27 #8 0.153 cacheable-request@2.1.4 #8 0.153 callsites@4.2.0 #8 0.153 caw@2.0.1 #8 0.153 change-file-extension@0.1.1 #8 0.153 clone-response@1.0.2 #8 0.153 color@4.2.3 #8 0.153 color-convert@2.0.1 #8 0.153 color-name@1.1.4 #8 0.153 color-string@1.9.1 #8 0.153 combined-stream@1.0.8 #8 0.153 commander@2.20.3 #8 0.153 commander@7.2.0 #8 0.153 config-chain@1.1.13 #8 0.153 content-disposition@0.5.4 #8 0.153 convert-hrtime@5.0.0 #8 0.153 core-util-is@1.0.3 #8 0.153 cross-spawn@5.1.0 #8 0.153 cross-spawn@6.0.5 #8 0.153 cross-spawn@7.0.3 #8 0.153 css-select@4.3.0 #8 0.153 css-tree@1.1.3 #8 0.153 css-what@6.1.0 #8 0.153 csso@4.2.0 #8 0.153 decode-uri-component@0.2.2 #8 0.153 decompress@4.2.1 #8 0.153 decompress-response@3.3.0 #8 0.153 decompress-tar@4.1.1 #8 0.153 decompress-tarbz2@4.1.1 #8 0.153 decompress-targz@4.1.1 #8 0.153 decompress-unzip@4.0.1 #8 0.153 delayed-stream@1.0.0 #8 0.153 detect-libc@2.0.3 #8 0.153 dom-serializer@1.4.1 #8 0.153 domelementtype@2.3.0 #8 0.153 domhandler@4.3.1 #8 0.153 domutils@2.8.0 #8 0.153 dot-prop@8.0.2 #8 0.153 download@6.2.5 #8 0.153 download@7.1.0 #8 0.153 duplexer3@0.1.5 #8 0.153 end-of-stream@1.4.4 #8 0.153 entities@2.2.0 #8 0.153 environment@1.1.0 #8 0.153 escape-string-regexp@1.0.5 #8 0.153 execa@0.7.0 #8 0.153 execa@1.0.0 #8 0.153 execa@5.1.1 #8 0.153 executable@4.1.1 #8 0.153 ext-list@2.2.2 #8 0.153 ext-name@5.0.0 #8 0.153 fast-equals@5.0.1 #8 0.153 fast-glob@3.3.2 #8 0.153 fast-xml-parser@4.5.0 #8 0.153 fastq@1.17.1 #8 0.153 fd-slicer@1.1.0 #8 0.153 file-type@3.9.0 #8 0.153 file-type@4.4.0 #8 0.153 file-type@5.2.0 #8 0.153 file-type@6.2.0 #8 0.153 file-type@8.1.0 #8 0.153 file-type@10.11.0 #8 0.153 file-type@19.5.0 #8 0.153 filename-reserved-regex@2.0.0 #8 0.153 filenamify@2.1.0 #8 0.153 fill-range@7.1.1 #8 0.153 find-versions@3.2.0 #8 0.153 follow-redirects@1.15.9 #8 0.153 form-data@4.0.0 #8 0.153 from2@2.3.0 #8 0.153 fs-constants@1.0.0 #8 0.153 function-timeout@1.0.2 #8 0.153 get-proxy@2.1.0 #8 0.153 get-stream@2.3.1 #8 0.153 get-stream@3.0.0 #8 0.153 get-stream@4.1.0 #8 0.153 get-stream@6.0.1 #8 0.153 get-stream@9.0.1 #8 0.153 gifsicle@5.3.0 #8 0.153 glob-parent@5.1.2 #8 0.153 globby@14.0.2 #8 0.153 got@7.1.0 #8 0.153 got@8.3.2 #8 0.153 graceful-fs@4.2.11 #8 0.153 has-symbol-support-x@1.4.2 #8 0.153 has-to-string-tag-x@1.4.1 #8 0.153 hono@4.5.11 #8 0.153 http-cache-semantics@3.8.1 #8 0.153 human-signals@2.1.0 #8 0.153 identifier-regex@1.0.0 #8 0.153 ieee754@1.2.1 #8 0.153 ignore@5.3.2 #8 0.153 imagemin@9.0.0 #8 0.153 imagemin-gifsicle@7.0.0 #8 0.153 imagemin-svgo@10.0.1 #8 0.153 import-lazy@3.1.0 #8 0.153 inherits@2.0.4 #8 0.153 ini@1.3.8 #8 0.153 into-stream@3.1.0 #8 0.153 is-arrayish@0.3.2 #8 0.153 is-extglob@2.1.1 #8 0.153 is-gif@3.0.0 #8 0.153 is-glob@4.0.3 #8 0.153 is-identifier@1.0.1 #8 0.153 is-natural-number@4.0.1 #8 0.153 is-number@7.0.0 #8 0.153 is-object@1.0.2 #8 0.153 is-plain-obj@1.1.0 #8 0.153 is-retry-allowed@1.2.0 #8 0.153 is-stream@1.1.0 #8 0.153 is-stream@2.0.1 #8 0.153 is-stream@4.0.1 #8 0.153 is-svg@4.4.0 #8 0.153 isarray@1.0.0 #8 0.153 isexe@2.0.0 #8 0.153 isurl@1.0.0 #8 0.153 json-buffer@3.0.0 #8 0.153 junk@4.0.1 #8 0.153 keyv@3.0.0 #8 0.153 lowercase-keys@1.0.0 #8 0.153 lowercase-keys@1.0.1 #8 0.153 lru-cache@4.1.5 #8 0.153 make-dir@1.3.0 #8 0.153 mdn-data@2.0.14 #8 0.153 merge-stream@2.0.0 #8 0.153 merge2@1.4.1 #8 0.153 micromatch@4.0.8 #8 0.153 mime-db@1.52.0 #8 0.153 mime-types@2.1.35 #8 0.153 mimic-fn@2.1.0 #8 0.153 mimic-response@1.0.1 #8 0.153 nice-try@1.0.5 #8 0.153 normalize-url@2.0.1 #8 0.153 npm-conf@1.1.3 #8 0.153 npm-run-path@2.0.2 #8 0.153 npm-run-path@4.0.1 #8 0.153 nth-check@2.1.1 #8 0.153 object-assign@4.1.1 #8 0.153 once@1.4.0 #8 0.153 onetime@5.1.2 #8 0.153 os-filter-obj@2.0.0 #8 0.153 ow@2.0.0 #8 0.153 p-cancelable@0.3.0 #8 0.153 p-cancelable@0.4.1 #8 0.153 p-event@1.3.0 #8 0.153 p-event@2.3.1 #8 0.153 p-finally@1.0.0 #8 0.153 p-is-promise@1.1.0 #8 0.153 p-map-series@1.0.0 #8 0.153 p-pipe@4.0.0 #8 0.153 p-reduce@1.0.0 #8 0.153 p-timeout@1.2.1 #8 0.153 p-timeout@2.0.1 #8 0.153 path-key@2.0.1 #8 0.153 path-key@3.1.1 #8 0.153 path-type@5.0.0 #8 0.153 peek-readable@5.2.0 #8 0.153 pend@1.2.0 #8 0.153 picocolors@1.1.0 #8 0.153 picomatch@2.3.1 #8 0.153 pify@2.3.0 #8 0.153 pify@3.0.0 #8 0.153 pify@4.0.1 #8 0.153 pinkie@2.0.4 #8 0.153 pinkie-promise@2.0.1 #8 0.153 prepend-http@1.0.4 #8 0.153 prepend-http@2.0.0 #8 0.153 process-nextick-args@2.0.1 #8 0.153 proto-list@1.2.4 #8 0.153 proxy-from-env@1.1.0 #8 0.153 pseudomap@1.0.2 #8 0.153 pump@3.0.0 #8 0.153 query-string@5.1.1 #8 0.153 queue-microtask@1.2.3 #8 0.153 readable-stream@2.3.8 #8 0.153 reserved-identifiers@1.0.0 #8 0.153 responselike@1.0.2 #8 0.153 reusify@1.0.4 #8 0.153 run-parallel@1.2.0 #8 0.153 safe-buffer@5.1.2 #8 0.153 safe-buffer@5.2.1 #8 0.153 seek-bzip@1.0.6 #8 0.153 semver@5.7.2 #8 0.153 semver@7.6.3 #8 0.153 semver-regex@2.0.0 #8 0.153 semver-truncate@1.1.2 #8 0.153 sharp@0.33.5 #8 0.153 shebang-command@1.2.0 #8 0.153 shebang-command@2.0.0 #8 0.153 shebang-regex@1.0.0 #8 0.153 shebang-regex@3.0.0 #8 0.153 signal-exit@3.0.7 #8 0.153 simple-swizzle@0.2.2 #8 0.153 slash@5.1.0 #8 0.153 sort-keys@1.1.2 #8 0.153 sort-keys@2.0.0 #8 0.153 sort-keys-length@1.0.1 #8 0.153 source-map@0.6.1 #8 0.153 stable@0.1.8 #8 0.153 strict-uri-encode@1.1.0 #8 0.153 string_decoder@1.1.1 #8 0.153 strip-dirs@2.1.0 #8 0.153 strip-eof@1.0.0 #8 0.153 strip-final-newline@2.0.0 #8 0.153 strip-outer@1.0.1 #8 0.153 strnum@1.0.5 #8 0.153 strtok3@8.1.0 #8 0.153 super-regex@1.0.0 #8 0.153 svgo@2.8.0 #8 0.153 tar-stream@1.6.2 #8 0.153 temp-dir@1.0.0 #8 0.153 tempfile@2.0.0 #8 0.153 through@2.3.8 #8 0.153 time-span@5.1.0 #8 0.153 timed-out@4.0.1 #8 0.153 to-buffer@1.1.1 #8 0.153 to-regex-range@5.0.1 #8 0.153 token-types@6.0.0 #8 0.153 trim-repeated@1.0.0 #8 0.153 tslib@2.7.0 #8 0.153 tunnel-agent@0.6.0 #8 0.153 type-fest@3.13.1 #8 0.153 typescript@5.6.2 #8 0.153 uint8array-extras@1.4.0 #8 0.153 unbzip2-stream@1.4.3 #8 0.153 undici-types@5.26.5 #8 0.153 undici-types@6.19.8 #8 0.153 unicorn-magic@0.1.0 #8 0.153 url-parse-lax@1.0.0 #8 0.153 url-parse-lax@3.0.0 #8 0.153 url-to-options@1.0.1 #8 0.153 util-deprecate@1.0.2 #8 0.153 uuid@3.4.0 #8 0.153 which@1.3.1 #8 0.153 which@2.0.2 #8 0.153 wrappy@1.0.2 #8 0.153 xtend@4.0.2 #8 0.153 yallist@2.1.2 #8 0.153 yauzl@2.10.0 #8 0.153 zod@3.23.8 #8 0.153 -- END HASH-- #8 0.154 Saving 39 trees #8 0.154 Saving 316 hoisted_dependencies #8 0.154 Saving 398 resolutions #8 0.154 Saving 398 dependencies #8 0.154 Saving 8 extern_strings #8 0.154 Saving 21[274](https://github.com/rohit-nayak123/compresspics/actions/runs/10792576105/job/29932530141#step:5:279) string_bytes #8 0.154 Saved lockfile

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

#9 [ 6/10] RUN bunx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp
#9 0.067 Resolving dependencies
#9 0.169 Resolved, downloaded and extracted [4]
#9 0.170 Saved lockfile
#9 0.253 
#9 0.253   System:
#9 0.253     OS: Linux 6.5 Alpine Linux
#9 0.253     CPU: (4) x64 AMD EPYC 7763 64-Core Processor
#9 0.253     Memory: 13.04 GB / 15.61 GB
#9 0.253     Container: Yes
#9 0.253     Shell: 1.36.1 - /bin/ash
#9 0.253   Binaries:
#9 0.253     bun: 1.1.28 - /tmp/bun-node-036e03034/bun
#9 0.253   npmPackages:
#9 0.253     sharp: ^0.33.5 => 0.33.5 
lovell commented 2 months ago

Bun does not support musl-based Alpine.

https://github.com/rohit-nayak123/compresspics/commit/15f605f8561e1497980a5442e59f7d53bf86b315

Please see https://github.com/oven-sh/bun/issues/918

rohit-nayak123 commented 2 months ago

So which bun image I should use for my project, any suggestions?

lovell commented 2 months ago

I'd probably revert commit https://github.com/rohit-nayak123/compresspics/commit/15f605f8561e1497980a5442e59f7d53bf86b315 as Debian Linux uses glibc, which is supported by Bun. (I'm unsure why Bun provides a musl-based image when it isn't officially supported.)

rohit-nayak123 commented 2 months ago

Wow, it worked! I followed your advice and removed --target=bun-linux-x64-baseline from the bun build command, and now it's working as before. Thanks for quick response.

todor0v commented 1 month ago

Hello @lovell! Can I please ask you for your opinion on an alternative solution for the same issue. I am currently using a Docker container for Next.js. However, I switched from node:18-alpine to oven/bun:alpine (bun alpine).

I faced the same error and I managed to solve it by adding this line to my Dockerfile:

RUN apk add --no-cache libstdc++ vips

I am also mentioning that I removed the line RUN apk add --no-cache libc6-compat since it also relies on glibc. I am not sure if I will need it in the future.

Am I likely to face more issues in the future and do you still recommend switching to a distro which supports glibc? For example Debian Slim.

lovell commented 1 month ago

@todor0v Bun does not currently support musl-based Linux, please subscribe to https://github.com/oven-sh/bun/issues/918 for updates.