Recently
gatsby-plugin-prefetch-google-fonts
one of the Gatsby plugin that I have been
using in this blog to pre-fetch google fonts during build become deprecated
and stopped working in newer versions of Gatsby.
So I searched for its alternatives and found
gatsby-plugin-preload-fonts
.
It is an official plugin so it should be good (Atleast thats what I like to think). Unlike previous
plugin which pre-fetch fonts defines in gatsby-config.js
, it spins up a Puppeteer
instance and visits each of your application’s routes to determine the required font assets
and generate font catch config.
If you don’t know what Puppeteer is then let me explain in brief, it is a Node library which provides a high-level API to control Chrome or Chromium by running a headless (by default) browser instance. In our case it is used to find scrap font assets from gatsby application.
I was using ClearLinux in WSL2 for developing this blog so I suspect that running Chrome/Chromium headless out of box might be difficult. Well, I was right about that, running plugin throws node exception.
Above error clear state that chrome
executable from Puppeteer cannot find libasound.so
shared library. That might be because I didn’t install xorg related packages in WSL2.
To fix this simply find the clearlinux bundle which contains libasound.so
using swupd
(ClearLinux package manager).
Installing any of the listed bundles will fix the missing shared library error.
To my surprise even after fixing all of the shared library missing errors,
plugin was not working.
So I try to directly run chrome
executable in headless mode.
Well, looks like fontconfig
cannot find default config file i.e fonts.conf.
In most distros default fonts.conf
is usually located in /etc/fonts.conf
but
since ClearLinux is designed for being stateless (Operate without any custom
configuration, for example, a generic host with an empty /etc directory. Stateless
systems strictly separate the OS configuration, the per-system configuration, and
the VT user-data stored on that system.). That being the case /etc
is not used for
default system files in ClearLinux. But since I already installed
fonts-basic
bundle I was sure
that fontconfig
is present so do fonts.conf
file.
I search for the file in /usr and found it at “/usr/share/defaults/fonts/fonts.conf”.
Setting the FONTCONFIG_PATH
to the directory where font.conf
solved the problem.
(or you can just copy the font.conf
to /etc
)