cat articles/wsl-sharp
When sharp fails to install on WSL
This was a small but annoying trap. When I ran yarn add sharp on Linux inside WSL2, sharp started trying to build itself locally and failed with:
"/usr/include/vips/vips8:35:10: fatal error: glib-object.h:"
The confusing part was that the libvips-related packages existed, and /usr/include/glib-2.0/glib-object.h existed too. I tried several things, but none of them fixed it.
Looking more carefully at the other error messages, I found that it first failed here:
sharp: Installation error: ENOENT: no such file or directory, mkdir 'C:\Users\hotch\AppData\Roaming/npm-cache'
After that failure, it tried to start a local build. But why was Linux inside WSL referring to a Windows path in the first place? Looking at the environment, I found that the APPDATA environment variable was being passed into WSL as-is, and that path was coming from there.
In sharp's install code, the cache path includes env.APPDATA, which made it refer to the odd Windows path.
When I set APPDATA to an empty string, which evaluates as false in Node.js, sharp used the prebuilt Linux binary from the cache and installed successfully.
APPDATA='' yarn add sharp
This does not fix the underlying local-build problem, but sharp became usable, so that was good enough for now.