Hi!
I'm getting Cannot find module '../build/Release/sharp-linuxmusl-x64.node' exception when I try to use sharp. All installation questions are answered below. First, my description of the issue:
My setup:
- using
pnpm
- I run my
pnpm i command in Ubuntu in WSL
- My Astro app runs in an Alpine Linux container - specifically based on
node:21-alpine. My local directory is mounted to the container.
Everything is working okay, if I switch the base image form node:21-alpine to node:21. I can't get Sharp to work in Alpine Linux, even though I've configured the supportedArchitectures:
"pnpm": {
"supportedArchitectures": {
"libc": [
"glibc",
"musl"
]
}
}
and Vite build options:
rollupOptions: {
external: ['sharp'],
}
I've tried running:
- rm pnpm-lock.yaml
- sudo rm -rf node_modules
- pnpm store prune
- pnpm i --force
- docker compose up --build astroapp
But I'm still getting the Cannot find module '../build/Release/sharp-linuxmusl-x64.node' error.
I suspect that the error is in sharp rather than in pnpm, because during pnpm i --force, I can see that some musl packages are being downloaded:
WARN using --force I sure hope you know what you are doing
Downloading registry.npmjs.org/typescript/5.4.3: 5.82 MB/5.82 MB, done
Progress: resolved 213, reused 72, downloaded 120, added 0
Downloading registry.npmjs.org/@img/sharp-libvips-linux-s390x/1.0.2: 6.40 MB/6.40 MB, done
Downloading registry.npmjs.org/@img/sharp-libvips-linux-arm/1.0.2: 6.21 MB/6.21 MB, done
Downloading registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/1.0.2: 7.10 MB/7.10 MB, done
Downloading registry.npmjs.org/@img/sharp-libvips-linux-x64/1.0.2: 7.06 MB/7.06 MB, done
Downloading registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/1.0.2: 7.20 MB/7.20 MB, done
Downloading registry.npmjs.org/@img/sharp-win32-ia32/0.33.3: 8.36 MB/8.36 MB, done
Downloading registry.npmjs.org/@img/sharp-libvips-linux-arm64/1.0.2: 7.07 MB/7.07 MB, done
Downloading registry.npmjs.org/@img/sharp-win32-x64/0.33.3: 8.40 MB/8.40 MB, done
Downloading registry.npmjs.org/@img/sharp-libvips-darwin-arm64/1.0.2: 7.02 MB/7.02 MB, done
Progress: resolved 485, reused 172, downloaded 291, added 0
The error occurs when Astro tries to load sharp:
sharpImport = (await import("sharp")).default;
It throws the Cannot find module '../build/Release/sharp-linuxmusl-x64.node' exception.
Possible install-time or require-time problem
Are you using the latest version of sharp?
Are you using a supported runtime?
I've tried Node 20.12.0 and 21.7.1. Same issue.
Are you using a supported package manager and installing optional dependencies?
What is the complete error message, including the full stack trace?
astroapp-1 | Something went wrong installing the "sharp" module
astroapp-1 |
astroapp-1 | Cannot find module '../build/Release/sharp-linuxmusl-x64.node'
astroapp-1 | Require stack:
astroapp-1 | - /app/node_modules/.pnpm/sharp@0.32.6/node_modules/sharp/lib/sharp.js
astroapp-1 | - /app/node_modules/.pnpm/sharp@0.32.6/node_modules/sharp/lib/constructor.js
astroapp-1 | - /app/node_modules/.pnpm/sharp@0.32.6/node_modules/sharp/lib/index.js
astroapp-1 |
astroapp-1 | Possible solutions:
astroapp-1 | - Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
astroapp-1 | - Install for the current linuxmusl-x64 runtime: "npm install --platform=linuxmusl --arch=x64 sharp"
astroapp-1 | - Consult the installation documentation: https://sharp.pixelplumbing.com/install
astroapp-1 | at Object.<anonymous> (/app/node_modules/.pnpm/sharp@0.32.6/node_modules/sharp/lib/sharp.js:37:9)
astroapp-1 | at Module._compile (node:internal/modules/cjs/loader:1368:14)
astroapp-1 | at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
astroapp-1 | at Module.load (node:internal/modules/cjs/loader:1205:32)
astroapp-1 | at Module._load (node:internal/modules/cjs/loader:1021:12)
astroapp-1 | at Module.require (node:internal/modules/cjs/loader:1230:19)
astroapp-1 | at require (node:internal/modules/helpers:179:18)
astroapp-1 | at Object.<anonymous> (/app/node_modules/.pnpm/sharp@0.32.6/node_modules/sharp/lib/constructor.js:11:1)
astroapp-1 | at Module._compile (node:internal/modules/cjs/loader:1368:14)
astroapp-1 | at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
What is the complete output of running npm install --verbose --foreground-scripts sharp in an empty directory?
It's too long for GitHub, so I've uploaded it to JumpShare: https://jmp.sh/9jppp81J
What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?
Need to install the following packages:
envinfo@7.11.1
Ok to proceed? (y)
System:
OS: Linux 5.15 Ubuntu 20.04.5 LTS (Focal Fossa)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Memory: 10.51 GB / 15.49 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 20.8.1 - ~/.nvm/versions/node/v20.8.1/bin/node
Yarn: 1.22.19 - ~/.yarn/bin/yarn
npm: 10.2.1 - ~/.nvm/versions/node/v20.8.1/bin/npm
pnpm: 8.15.6 - ~/.local/share/pnpm/pnpm
bun: 1.0.7 - ~/.local/share/pnpm/bun
Hi!
I'm getting
Cannot find module '../build/Release/sharp-linuxmusl-x64.node'exception when I try to use sharp. All installation questions are answered below. First, my description of the issue:My setup:
pnpmpnpm icommand in Ubuntu in WSLnode:21-alpine. My local directory is mounted to the container.Everything is working okay, if I switch the base image form
node:21-alpinetonode:21. I can't get Sharp to work in Alpine Linux, even though I've configured the supportedArchitectures:and Vite build options:
I've tried running:
But I'm still getting the
Cannot find module '../build/Release/sharp-linuxmusl-x64.node'error.I suspect that the error is in
sharprather than inpnpm, because duringpnpm i --force, I can see that somemuslpackages are being downloaded:The error occurs when Astro tries to load
sharp:It throws the
Cannot find module '../build/Release/sharp-linuxmusl-x64.node'exception.Possible install-time or require-time problem
Are you using the latest version of sharp?
sharpas reported bynpm view sharp dist-tags.latest.Are you using a supported runtime?
^18.17.0 || ^20.3.0 || >=21.0.0I've tried Node
20.12.0and21.7.1.Same issue.Are you using a supported package manager and installing optional dependencies?
--include=optional--no-optional=falseWhat is the complete error message, including the full stack trace?
What is the complete output of running
npm install --verbose --foreground-scripts sharpin an empty directory?It's too long for GitHub, so I've uploaded it to JumpShare: https://jmp.sh/9jppp81J
What is the output of running
npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?