Navigate back to the homepage

Running Puppeteer in WSL2 ClearLinux

Ashutosh Varma
December 20th, 2020 · 1 min read

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.

Error while running preload plugin - 'yarn preload-fonts'
shared library not found while running preload plugin - 'yarn preload-fonts'

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).

Error while running preload plugin - 'yarn preload-fonts'
shared library not found while running preload plugin - 'yarn preload-fonts'

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.

Error while running preload plugin - 'yarn preload-fonts'
fontconfig cannot find default config error

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.

Searching for fonts.conf in /usr
Searching for fonts.conf in /usr

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)

Successfully running plugin
Searching for fonts.conf in /usr

Join our email list and get notified about new content

Be the first to receive our latest content with the ability to opt-out at anytime. We promise to not spam your inbox or share your email with any third parties.

More articles from Ashutosh Varma

Timeout on function call in Python

For the past few days I was working on dfit , a python module which find the best probability distribution for your observations. Luckily…

December 16th, 2020 · 3 min read

How to backup and restore your PGP keys with GPG ?

Backup the public and secret keyrings and trust database For minimal backup you only need to save your private key, assuming your public key…

August 20th, 2020 · 1 min read
© 2020 Ashutosh Varma
Link to $https://github.com/ashutoshvarmaLink to $https://www.linkedin.com/in/varmaashutosh/Link to $https://stackoverflow.com/users/13944127/Link to $mailto:ashutoshvarma11@live.com