How to fix puppetteer error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory

Problem:

You are trying to run puppetteer on Ubuntu, but when it starts to run chrome, you are facing the following issue:

/home/user/erp/node_modules/puppeteer/.local-chromium/linux-555668/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory

Solution

Install the missing packages using

On Ubuntu 22.04:

sudo apt install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

On Ubuntu 24.04:

sudo apt install -y liboss4-salsa-asound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc-s1 libgdk-pixbuf-2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator3-1 libnss3 lsb-release xdg-utils wget

On OpenSUSE 15.5:

sudo zypper install -y alsa-lib atk glibc cairo cups-libs dbus-1 expat fontconfig libgcc_s1 gdk-pixbuf glib2 gtk3 mozilla-nspr pango libstdc++6 libX11-6 libX11-xcb1 libxcb1 libXcomposite1 libXcursor1 libXdamage1 libXext6 libXfixes3 libXi6 libXrandr2 libXrender1 libXss1 libXtst6 ca-certificates liberation-fonts libappindicator3-1 mozilla-nss lsb-release xdg-utils wget
``

Credits to [@coldner](https://github.com/coldner) on [the puppetteer issue tracker](https://github.com/Googlechrome/puppeteer/issues/290) for assembling the required pkgs.

If you encounterĀ `E: Unable to locate package` errors, run `sudo apt-get update`.

### Background information

If you want to know more on why this issue occurs, continue reading here.

Puppetteer is essentially a minimal *headless* (seeĀ [What is a headless program or application?](https://techoverflow.net/2019/05/17/what-is-a-headless-program-or-application/)) Chromium instance with an additional API for controlling and monitoring it from NodeJS.

Even though Puppetteer does not actually display a GUI, the Chromium instance it uses still requires some of the libraries to draw a GUI and connect to the *X11* server, even though that isn't used in Puppetteer. One of those libraries is `libxcb` which provides the shared library `libX11-xcb.so.1`. You can fix this by installing the `libx11-xcb1` package on most Debian-based systems.

However, as it is so often the case with missing shared libraries, once you install the one that is missing, there will be *at least*one other library missing after that. That's why we need to install the large number of libraries listed above.