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.

cat related_articles/wsl-sharp.yaml

  1. trn: A Fast Local Translation Command for macOS Tahoetrn is a macOS CLI for Apple's on-device Translation framework, with a low-latency mode about 12x faster than high-fidelity mode in a local README test.
  2. Adding type hints to a Python project and getting value from type checkingAdding Python type hints and pyright to a machine learning project, with a low setup cost and immediately useful editor support and static checks.
  3. Reading Basic Statistics by Kimio Miyakawa: statistics before machine learningWhy statistical foundations matter for understanding data, experiments, estimation, hypothesis testing, and machine learning model evaluation.