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

0.33.2: pnpm: Error: Could not load the "sharp" module using the linux-x64 runtime #4012

Closed
5 tasks done
brenc opened this issue Feb 28, 2024 · 4 comments
Closed
5 tasks done

Comments

@brenc
Copy link

brenc commented Feb 28, 2024

When I install via pnpm I cannot import sharp@^0.33.2. However, sharp@0.32.6 loads as expected.

Possible install-time or require-time problem

Require time. Test script:

import sharp from 'sharp';

const resizeImage = async (inputPath, outputPath, width, height) => {
  await sharp(inputPath)
    .resize(width, height)
    .toFile(outputPath);
};

package.json:

{
  "name": "s",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "volta": {
    "node": "20.11.1"
  },
  "type": "module",
  "dependencies": {
    "sharp": "^0.33.2"
  }
}

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.

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

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

$ pnpm -v
8.15.4

$ pnpm add --no-optional=false sharp@latest
Already up to date
Progress: resolved 32, reused 15, downloaded 0, added 0, done
Done in 601ms
  • I am using pnpm >= 7.1.0 with --no-optional=false

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

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
    yarn add sharp --ignore-engines
- 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 Object.<anonymous> (/home/bcolby/dev/ngchat/s/node_modules/.pnpm/sharp@0.33.2/node_modules/sharp/lib/sharp.js:114:9)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/home/bcolby/dev/ngchat/s/node_modules/.pnpm/sharp@0.33.2/node_modules/sharp/lib/constructor.js:10:1)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)

Node.js v20.11.1

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

When I install sharp via npm it imports as expected.

$ npm install --verbose --foreground-scripts sharp
npm verb cli /home/bcolby/.volta/tools/image/node/20.11.1/bin/node /home/bcolby/.volta/tools/image/node/20.11.1/bin/npm
npm info using npm@10.2.4
npm info using node@v20.11.1
npm verb title npm install sharp
npm verb argv "install" "--loglevel" "verbose" "--foreground-scripts" "sharp"
npm verb logfile logs-max:10 dir:/home/bcolby/.npm/_logs/2024-02-28T06_57_10_481Z-
npm verb logfile /home/bcolby/.npm/_logs/2024-02-28T06_57_10_481Z-debug-0.log
npm http fetch GET 200 https://registry.npmjs.org/sharp 8ms (cache hit)
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-win32-x64
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-win32-ia32
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-wasm32
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@emnapi/runtime
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/tslib
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-linuxmusl-arm64
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-linux-s390x
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-linux-arm64
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-linux-arm
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-libvips-linuxmusl-arm64
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-libvips-linux-s390x
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-libvips-linux-arm64
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-libvips-linux-arm
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-libvips-darwin-x64
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-libvips-darwin-arm64
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-darwin-x64
npm verb reify failed optional dependency /home/bcolby/dev/ngchat/s/node_modules/@img/sharp-darwin-arm64
npm info run sharp@0.33.2 install node_modules/sharp node install/check

> sharp@0.33.2 install
> node install/check

npm info run sharp@0.33.2 install { code: 0, signal: null }
npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/advisories/bulk 359ms

added 15 packages, and audited 16 packages in 515ms

5 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
npm verb exit 0
npm info ok

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

$ npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp

  System:
    OS: Linux 5.10 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (8) x64 Intel(R) Xeon(R) E-2386G CPU @ 3.50GHz
    Memory: 4.45 GB / 13.65 GB
    Container: Yes
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 20.11.1 - ~/.volta/tools/image/node/20.11.1/bin/node
    Yarn: 4.1.0 - ~/.volta/tools/image/yarn/4.1.0/bin/yarn
    npm: 10.2.4 - ~/.volta/tools/image/node/20.11.1/bin/npm
    pnpm: 8.15.4 - ~/.volta/bin/pnpm
    bun: 1.0.4 - ~/.bun/bin/bun
  npmPackages:
    sharp: ^0.33.2 => 0.33.2
@lovell
Copy link
Owner

lovell commented Feb 28, 2024

I cannot reproduce this with pnpm locally. Does the node_modules/.pnpm directory contain @img+sharp-... directories for the optional dependencies relevant to the linux-x64 platform?

Do you see this problem if you don't use Volta? (I note https://docs.volta.sh/advanced/pnpm says "Support for pnpm is currently experimental.")

If you're still having problems, please provide a Dockerfile (or similar) to create an environment that allows someone else to reproduce.

@deadcoder0904

This comment was marked as off-topic.

@brenc
Copy link
Author

brenc commented Feb 28, 2024

OK I think I've figured out what's going on. I couldn't reproduce this in Docker either. On my dev system (Debian Bullseye) I tried running the sharp install script manually:

$ pnpm run install
 WARN  Unsupported engine: wanted: {"node":"^18.17.0 || ^20.3.0 || >=21.0.0"} (current: {"node":"v18.16.0","pnpm":"8.15.4"})

> sharp@0.33.2 install /home/bcolby/dev/ngchat/s/node_modules/.pnpm/sharp@0.33.2/node_modules/sharp
> node install/check

I think this perhaps was causing the install to fail so @img/sharp-linux-x64 wasn't getting installed. If I installed this package manually I could import sharp as expected. I swear I tried this last night but I must not have installed the right @img package.

For some reason pnpm was "stuck" on an old version of node even though I am currently pinned at 20. What fixed this for me was running (with node@20) npm i -g pnpm and then reinstalling sharp. Everything is working as expected now.

@brenc brenc closed this as completed Feb 28, 2024
@deadcoder0904
Copy link

i, also, figured out my problem with sharp, pnpm, & docker.

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

3 participants