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

WSL: Node.js 18 installed from Snap Store, Could not load the "sharp" module using the linux-x64 runtime #3884

Closed
4 of 10 tasks
eamodio opened this issue Dec 7, 2023 · 15 comments

Comments

@eamodio
Copy link

eamodio commented Dec 7, 2023

Possible install-time or require-time problem

I'm running into the same issue as #3870, but I'm running locally in WSL.

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.

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 >= 9.6.5 with --include=optional
  • I am using yarn >= 3.2.0 and I am not using the "Plug'n'Play" linker
  • 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 dependencies before opening an issue.

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

$ npm install --verbose --foreground-scripts sharp
npm verb cli /snap/node/7823/bin/node /snap/node/7823/bin/npm
npm info using npm@9.8.1
npm info using node@v18.18.0
npm verb title npm install sharp
npm verb argv "install" "--loglevel" "verbose" "--foreground-scripts" "sharp"
npm verb logfile logs-max:10 dir:/home/eric/.npm/_logs/2023-12-07T20_41_33_116Z-
npm verb logfile /home/eric/.npm/_logs/2023-12-07T20_41_33_116Z-debug-0.log
npm http fetch GET 200 https://registry.npmjs.org/sharp 92ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/detect-libc 33ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/semver 58ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color 80ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-arm64 199ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-wasm32 375ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linuxmusl-arm64 883ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linuxmusl-x64 893ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-darwin-arm64 900ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-arm 911ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-darwin-x64 930ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-s390x 928ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-win32-x64 950ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-x64 952ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-darwin-arm64 959ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-darwin-x64 959ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linux-s390x 960ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-x64 971ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linuxmusl-arm64 973ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-arm64 977ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-linux-arm 1282ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-libvips-linuxmusl-x64 1751ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img%2fsharp-win32-ia32 1803ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color-string 27ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color-convert 36ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/lru-cache 45ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@emnapi%2fruntime 919ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/tslib 40ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color-name 29ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color-name 34ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/simple-swizzle 39ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/is-arrayish 53ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/yallist 32ms (cache miss)
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-win32-x64
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-win32-ia32
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-wasm32
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@emnapi/runtime
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/tslib
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-linuxmusl-arm64
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-linux-s390x
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-linux-arm64
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-linux-arm
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-libvips-linuxmusl-arm64
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-libvips-linux-s390x
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-libvips-linux-arm64
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-libvips-linux-arm
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-libvips-darwin-x64
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-libvips-darwin-arm64
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-darwin-x64
npm verb reify failed optional dependency /home/eric/code/foo/node_modules/@img/sharp-darwin-arm64
npm http fetch GET 200 https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz 34ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color-string/-/color-string-1.9.1.tgz 40ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.2.tgz 39ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/color/-/color-4.2.3.tgz 43ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz 55ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/sharp/-/sharp-0.33.0.tgz 56ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.0.0.tgz 331ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.33.0.tgz 455ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@emnapi/runtime/-/runtime-0.44.0.tgz 456ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.33.0.tgz 458ms (cache miss)
npm http fetch GET 200 https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.0.0.tgz 593ms (cache miss)
npm info run sharp@0.33.0 install node_modules/sharp node install/check

sharp@0.33.0 install
node install/check

npm info run sharp@0.33.0 install { code: 0, signal: null }

added 15 packages in 4s

5 packages are looking for funding
run npm fund for details
npm verb exit 0
npm info ok

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

System:
    OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
    CPU: (32) x64 AMD Ryzen 9 7950X 16-Core Processor
    Memory: 21.94 GB / 30.91 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.18.0 - /snap/bin/node
    Yarn: 1.22.19 - /snap/bin/yarn
    npm: 9.8.1 - /snap/bin/npm
    pnpm: 8.7.0 - /mnt/c/Users/eric/AppData/Roaming/npm/pnpm
  npmPackages:
    sharp: ^0.33.0 => 0.33.0 
eamodio added a commit to gitkraken/vscode-gitlens that referenced this issue Dec 7, 2023
@lovell
Copy link
Owner

lovell commented Dec 7, 2023

Hi, please can you provide answers to all of the questions in the issue template.

@eamodio
Copy link
Author

eamodio commented Dec 7, 2023

@lovell Updated

@lovell
Copy link
Owner

lovell commented Dec 7, 2023

Thank you, please can you also provide the complete output of running node -e "require('sharp')" in the /home/eric/code/foo directory (it should provide an error message with stack trace and suggestions).

@eamodio
Copy link
Author

eamodio commented Dec 7, 2023

node -e "require('sharp')"
/home/eric/code/foo/node_modules/sharp/lib/sharp.js:85
  throw new Error(help.join('\n'));
  ^

Error: Could not load the "sharp" module using the linux-x64 runtime
ERR_DLOPEN_FAILED: /snap/core20/current/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /lib/x86_64-linux-gnu/libresolv.so.2)
Possible solutions:
- Add platform-specific dependencies:
    npm install --os=linux --cpu=x64 sharp
  or
    npm install --force @img/sharp-linux-x64
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
    at Object.<anonymous> (/home/eric/code/foo/node_modules/sharp/lib/sharp.js:85:9)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (/home/eric/code/foo/node_modules/sharp/lib/constructor.js:10:1)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)

Node.js v18.18.0

@lovell
Copy link
Owner

lovell commented Dec 7, 2023

Thank you, it looks like you're using Node.js installed from the Snap Store. nodejs/snap#54 suggests there are known problems relating to it partially linking to system libraries rather than core libraries, which rather defeats the point of snaps.

The output of ldd node_modules/@img/sharp-libvips-linux-x64/lib/libvips-cpp.so.42 should provide the list of libraries discovered and used at runtime.

@lovell lovell changed the title WSL: Could not load the "sharp" module using the linux-x64 runtime WSL: Node.js installed from Snap Store, Could not load the "sharp" module using the linux-x64 runtime Dec 7, 2023
@lovell
Copy link
Owner

lovell commented Dec 8, 2023

I've been able to reproduce this locally:

$ sudo snap install node --channel=18/stable --classic
$ /snap/bin/npm install sharp
$ /snap/node/current/bin/node -p "require('sharp')"
...
Error: Could not load the "sharp" module using the linux-x64 runtime
ERR_DLOPEN_FAILED: /snap/core20/current/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_ABI_DT_RELR' not found (required by /lib/x86_64-linux-gnu/libresolv.so.2)
...

Explicitly setting LD_LIBRARY_PATH ensures the shared libraries from core20 are used instead of system libraries so the following works correctly:

$ LD_LIBRARY_PATH=/snap/core20/current/lib/x86_64-linux-gnu /snap/node/current/bin/node -e "require('sharp')"

This relates to classic confinement, where every shared library under control of the snap is assumed to have an RPATH that points inside the snap-managed filesystem.

The prebuilt libvips binaries provided by sharp do not set RPATH, which is correct, as we want whatever is using them to control where system-level libraries should be found.

$ readelf -d node_modules/@img/sharp-libvips-linux-x64/lib/libvips-cpp.so.42 | grep -e RPATH -e NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libresolv.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]

In summary, using any native module with a snap-installed Node.js allows escape from classic confinement, which means you'll always need to ensure the version of core matches the version of the OS. For example, when using Ubuntu 22.04 provided by WSL, you should always use a Node.js snap that is dependent on core22.

@lovell lovell changed the title WSL: Node.js installed from Snap Store, Could not load the "sharp" module using the linux-x64 runtime WSL: Node.js 18 installed from Snap Store, Could not load the "sharp" module using the linux-x64 runtime Dec 8, 2023
@lovell
Copy link
Owner

lovell commented Dec 11, 2023

There are quite a few issues relating to this at https://github.com/nodejs/snap/issues

I've added some help text that will be displayed upon failure via commit 9e3b021

@lovell lovell closed this as completed Dec 11, 2023
@NormandoHall
Copy link

NormandoHall commented Dec 12, 2023

The same but not snap node:

Error: Could not load the "sharp" module using the linux-x64 runtime
ERR_DLOPEN_FAILED: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /opt/minerva/devel/node_modules/@img/sharp-linux-x64/lib/sharp-linux-x64.node)
Possible solutions:
- Add platform-specific dependencies:
    npm install --os=linux --cpu=x64 sharp
  or
    npm install --force @img/sharp-linux-x64
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
    at Object.<anonymous> (/opt/minerva/devel/node_modules/sharp/lib/sharp.js:85:9)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (/opt/minerva/devel/node_modules/sharp/lib/constructor.js:10:1)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)

Node.js v18.18.0

Installed and build on Centos 7 with Developer Toolset 7 as usual.
Maybe can fixed similar to this? #2119

@lovell
Copy link
Owner

lovell commented Dec 12, 2023

@NormandoHall As of sharp v0.33.0, the prebuilt binaries no longer support Centos 7.

https://sharp.pixelplumbing.com/install#prebuilt-binaries

lovell/sharp-libvips#176

@lovell
Copy link
Owner

lovell commented Dec 12, 2023

Commit c5eaeb2 will show help text relating to use of an outdated libc when this error message occurs.

@AlastairTaft

This comment was marked as off-topic.

@lovell
Copy link
Owner

lovell commented Dec 29, 2023

@AlastairTaft Please can you open a new installation issue and answer all of the questions.

@AlastairTaft

This comment was marked as off-topic.

@lovell
Copy link
Owner

lovell commented Dec 29, 2023

@AlastairTaft Pinning a dependency to a previous, unsupported version is unlikely to be the right long-term solution to a problem.

For anyone coming here - please open a new installation issue and answer all of the questions if you still require help.

(I'm hiding your comments as they introduce the L word to an issue that had previously never used it. This helps prevent search engines indexing this issue as relating to the L word. There are many other issues that do relate to the L word and I'd prefer people saw those first. I hope you understand.)

@AlastairTaft
Copy link

@lovell Totally agree its not a good long term solution. Just needed a quick way to get back up and running. Anyway, not a
problem, happy for you to triage my comment in the way you think is best appropriate. And love your package, I've used it many times over the years, thank you :)

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