I made a few tweaks to my website over the weekend – chief one being to decrease the static page refresh time and update packages, but ran into all sorts of problems trying to build the Docker image.
Error: Could not load the "sharp" module using the linuxmusl-arm runtime
Possible solutions:
- Manually install libvips >= 8.15.3
- Add experimental WebAssembly-based dependencies:
npm install --cpu=wasm32 sharp
npm install @img/sharp-wasm32
- Consult the installation documentation:
See https://sharp.pixelplumbing.com/install
at Object.
at Module._compile (node:internal/modules/cjs/loader:1740:14)
at Object..js (node:internal/modules/cjs/loader:1905:10)
at Module.load (node:internal/modules/cjs/loader:1474:32)
at Function._load (node:internal/modules/cjs/loader:1286:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:234:24)
at Module.
at mod.require (/app/node_modules/next/dist/server/require-hook.js:65:28)
at require (node:internal/modules/helpers:135:16)
> Build failed because of webpack errors
I have had this issue in the past (when I was first moving over to nextjs), but have built the site several times since then, but couldn’t for the life of me remember how to fix it. So I did all the usual stuff to fix it – cleared caches, updated packages… no joy. Builds and runs fine natively on the Pi itself, but the nextjs build fails in Docker with the above error no matter what.
After many hours going down a rabbit hole of node_modules
(which I thought was being copied, and causing the issue), it turns out it was all to do with how I was building the container. I had experimented in the past with a fancy cross-platform build (so I could build the Pi container on my Windows PC), which I subsequently abandoned but left the instructions in my Readme.
Drop the platform specification, and it builds perfectly.
I’m not sure why this is – I know cross platform builds can be… interesting shall we say, but I didn’t think I was doing a cross platform build! Anyway, all working now. (The reason I have the command in my Readme is that I also tag it and push it up to Docker repository).
Incidentally, Stack Overflow was no help – so this is posted in case someone else benefits from my pain!