image: bug: 1.3.0 could not load the sharp module
I’m not sure if this is a @nuxt/image, ipx, or sharp issue since updating to 1.3.0, @nuxt/image updates its ipx which also update its sharp.
Reproduction:
1.2.0 (Working): https://codesandbox.io/p/devbox/nuxt-image-1-2-0-build-output-8xnjr9 1.3.0 (Not working): https://codesandbox.io/p/devbox/nuxt-image-1-3-0-could-not-load-the-sharp-module-23zjtt
If needed, open a terminal in codesandbox to build and run it:
npm run build
node .output/server/index.mjs
You’ll see that 1.3.0 does not load the image in public directory properly with an error:
{
"error": {
"message": "[500] [IPX_ERROR] Could not load the \"sharp\" module using the linux-x64 runtime\nPossible solutions:\n- Ensure optional dependencies can be installed:\n npm install --include=optional sharp\n yarn add sharp --ignore-engines\n- Ensure your package manager supports multi-platform installation:\n See https://sharp.pixelplumbing.com/install#cross-platform\n- Add platform-specific dependencies:\n npm install --os=linux --cpu=x64 sharp\n- Consult the installation documentation:\n See https://sharp.pixelplumbing.com/install"
}
}
About this issue
- Original URL
- State: closed
- Created 5 months ago
- Reactions: 65
- Comments: 40 (3 by maintainers)
Commits related to this issue
- downgrade @nuxt/image version to 1.2.0 see: https://github.com/nuxt/image/issues/1210 — committed to traPtitech/game3-front by eyemono-moe 5 months ago
- fix: nuxt-image module not working via version 1.3.0 see: https://github.com/nuxt/image/issues/1210#issuecomment-1940568062 — committed to xuzuodong/personal-website by xuzuodong 4 months ago
@gorkie and others
Please refrain from posting comments that don’t add additional context like “+1”, “me too” or “bump”. Instead, just upvote the issue through reactions or provide additional context like a reproduction, a new scenario where it happens or anything else that helps resolving the issue.
Hey everyone! We are aware of the recent issues. The problem is how sharp bundles binaries for various platforms, especially causing issues when the prod environment is different than the dev/build environment.
Even downgrading my Nuxt to
3.9.1and Nuxt Image to1.2.0I’m still getting the same error.I’m on an M1 Mac, if that makes a difference.
It works for me without have to downgrade
@nuxt/imagepackage tov1.2.0, just pinning sharp to 0.32.6 and using Nodev20.3.0to pin sharp in package.json if you are using pnpm:
or using npm:
I can confirm that a downgrade of
@nuxt/imagetov1.2.0worked for me 👍🏼We are using yarn v1 and falling back to
sharp@0.32.6works as a temporary fix in our projects:This mechanism also exists for npm via
overrides(untested):yeah, same here. After locking the package to 1.2.0 it works again.
Hmm… I’m facing the same issue …
Edit: After reading the previous comments, finally this can be temporarily fixed by downgrading to
1.2.0I’ve did some digging and found that for pnpm, turning on
shamefully-hoist=truein.npmrcwill work andshamefully-hoist=falsewill not. And npm works no matter what.See:
true: https://codesandbox.io/p/devbox/shamefully-hoist-true-26fgzmfalse: https://codesandbox.io/p/devbox/shamefully-hoist-false-qgjhskThe reason can be as follows. In sharp it imported the runtime like such:
in https://github.com/lovell/sharp/blob/main/lib/sharp.js
When
shamefully-hoist=false,@img/sharp-xxxdoes not exist innode_modules/any more. Instead it’s innode_modules/.pnpm/@img+sharp-xxx.Which afterwards it returns the topic error.
Yeap I’m also facing this issue
I’m facing the same issue …
I also reproduced this in a docker using node-alpine:20, running on Ubuntu 20. Downgrading to 1.2.0 did not solve the issue.
EDIT: In my case, I was able to fix it, by re-installing
sharp(rebuild would do as well), since I was developing on Windows and Docker uses Linux.@Artem-Schander your lock file still shows version
"1.3.0". I assume that yourpackage.jsoncontains"@nuxt/image": "^1.2.0",. Using^as a prefix for the version will install the latest minor version.You will have to add
"@nuxt/image": "1.2.0",to stick to the desired version.For me this only happened in Docker environment. Using non-slim node images resolved our issue.
downgrading to
1.2.0got no problem with me deploying to linux with docker, but when deploying with multi stage build and distroless image, it showing error, here my DockerfileTried, no result.
+1
I’m facing the same issue on a Apple M1
In my case the issue was only when I run the app on the server, if I do
`npm run build
node .output/server/index.mjs`
everything works fine, the problem begins when I upload the build on a Centos9 and run it with PM2, there I get the:
{ "error": { "message": "[500] [IPX_ERROR] Could not load the \"sharp\" module using the linux-x64 runtime\nPossible solutions:\n- Ensure optional dependencies can be installed:\n npm install --include=optional sharp\n yarn add sharp --ignore-engines\n- Ensure your package manager supports multi-platform installation:\n See https://sharp.pixelplumbing.com/install#cross-platform\n- Add platform-specific dependencies:\n npm install --os=linux --cpu=x64 sharp\n- Consult the installation documentation:\n See https://sharp.pixelplumbing.com/install" } }The only thing that changed something a bit was to put
"@nuxt/image": "1.2.0"on my package.json dependencies.On my local machine everything still run smoothly, but if I upload the build on the server the error now is:
{"error":{"message":"[500] [IPX_ERROR] \nSomething went wrong installing the \"sharp\" module\n\nCannot find module '../build/Release/sharp-linux-x64.node'\nRequire stack:\n- /usr/share/nginx/html/default/public/frontend/server/node_modules/sharp/lib/sharp.js\n- /usr/share/nginx/html/default/public/frontend/server/node_modules/sharp/lib/constructor.js\n- /usr/share/nginx/html/default/public/frontend/server/node_modules/sharp/lib/index.js\n\nPossible solutions:\n- Install with verbose logging and look for errors: \"npm install --ignore-scripts=false --foreground-scripts --verbose sharp\"\n- Install for the current linux-x64 runtime: \"npm install --platform=linux --arch=x64 sharp\"\n- Consult the installation documentation: https://sharp.pixelplumbing.com/install"}}Unfortunately, it didn’t help me… in fact, it’s a pity that the minor version completely disables the library…
you’re right. should have noticed myself. sorry for the noise.
Yeah,
ipx3.0 +sharp0.33 = bad.Tried pinning
sharpto 0.32 - still broken.Only downgrading back to nuxt/image 1.2.x resolves it (which resolves to ipx 2.x and sharp 0.32)