After spending hours trying to figure out why my CI/CD pipeline seemingly couldn't download the SWC binary for my node alpine image, I decided to take a look at the "failed loading SWC" page in the NextJs docs and try a few of their suggestions.
(Yes, I tried cleaning the npm cache via npm cache clean --force
and even just simply deleting my node_modules
and package-lock.json
and then re-installing, but none of the suggestions worked.)
I was originally getting some nasty error when next-swc was downloading:
ZlibError: zlib: unexpected end of file
that pointed me to node_modules/next/next-swc-fallback/@next/swc-linux-x64-musl
that it was unable to decompress, but it turns out I was reading too much into this error, when it was an error with my install step.
In the line where I ran npm install
in my pipeline script, I had a the --no-optional
flag (i.e. npm i --no-optional
).
Once I removed the --no-optional
flag as suggested by the docs, the cryptic ZlibError
went away and my pipeline completed.
Hopes this saves you some hours search around about a ZlibError
for nothing!