all seems to be working well on netlify, but I am facing issues working locally. Redirects seems to have broken - for example, I have the following redirect in the netlify.toml
[[redirects]]
# ...or serve a resized version
from = "/cdn/:width/*"
to = "/.netlify/images?url=/images/:splat&width=:width"
status = 200
and it’s failing, example when I visit http://localhost:8888/cdn/120/trustpilot-white.png in the CLI I get:
ERROR '/cdn/120/trustpilot-white.png' not found.
opening that url in the page returns the following json file:
{
"error": {
"message": "[500] [IPX_ERROR] \nSomething went wrong installing the \"sharp\" module\n\nCannot find module '../build/Release/sharp-darwin-arm64v8.node'\nRequire stack:\n- /Users/andrea.dellacorte/Documents/Github/techinterview.coach/node_modules/.pnpm/sharp@0.32.6/node_modules/sharp/lib/sharp.js\n- /Users/andrea.dellacorte/Documents/Github/techinterview.coach/node_modules/.pnpm/sharp@0.32.6/node_modules/sharp/lib/constructor.js\n- /Users/andrea.dellacorte/Documents/Github/techinterview.coach/node_modules/.pnpm/sharp@0.32.6/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 darwin-arm64v8 runtime: \"npm install --platform=darwin --arch=arm64v8 sharp\"\n- Consult the installation documentation: https://sharp.pixelplumbing.com/install"
}
}
I have recently moved from npm to pnpm; can that be the cause?
Ok, so the build path is the path where the Sharp package is trying to resolve the compiled package to run. Since this is a Netlify function the sharp package needs to be packaged with the function. This is typically done by using a package.json in the function and it get’s included when the function compiles.
Not sure what’s going on with this build, since I don’t have a copy and see the paths being built. Another issue is Netlify CLI does some custom path copying during local dev that I haven’t unraveled for myself, because I typically handle it myself.
This won’t make you feel better, but Sharp is famous for all these issues and I stopped using it a long time ago.
Good news is that I can now see my images when I run npx netlify dev; I can see them working in the page and I can load them if I type the the address to them via the cdn redirect…
Bad news is… I still get a lot of errors from netlify cli?
[2025-01-16 22:45:21] ERROR '/cdn/16/companies/back.png' not found.
◈ Rewrote URL to /.netlify/images?url=/images/companies/back.png&width=16
also, I have a redirect from / to /tech which has always worked and would automagically redirect me when I loaded the netlify localhost:8888 url… and that’s not happening anymore (didn’t work on pnpm either).