54

I'm setting up the CI job for automated testing in selenium inside Gitlab CI, but the test is failing due to the issue.

019-09-27T11:03:17.404Z INFO @wdio/cli:Launcher: Run onPrepare hook /builds/shauryav/test-react-ci-cd/node_modules/chromedriver/lib/chromedriver/chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

I have tried numbers of solutions like installing package "@wdio/cli": "^5.13.2", "webdriverio": "^5.13.2" but nothing works. For the note, I'm not using any docker setup

/builds/shauryav/test-react-ci-cd/node_modules/chromedriver/lib/chromedriver/chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
2019-09-27T11:03:27.415Z ERROR @wdio/cli:utils: A service failed in the 'onPrepare' hook
Error: timeout
    at Timeout.timeoutFunc (/builds/shauryav/test-react-ci-cd/node_modules/tcp-port-used/index.js:204:25)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)```
shaurya
  • 581
  • 1
  • 4
  • 8
  • libnss3.so: No such file or directory → Install libnss (Debian, Ubuntu) / nss (Fedora, CentOS). – Knud Larsen Sep 28 '19 at 14:00
  • @KnudLarsen Unable to locate package libnss on ubuntu:16.04 – ghazouan badr Nov 15 '19 at 09:09
  • 2
    **16.04 : libnss3** .... `apt-cache search libnss` and `apt-file search libnss3.so` .... or use the on-line search https://packages.ubuntu.com/search?keywords=libnss&searchon=names ... to decide package name. – Knud Larsen Nov 15 '19 at 11:41

3 Answers3

82

try these command

apt install libnss

apt install libnss3-dev libgdk-pixbuf2.0-dev libgtk-3-dev libxss-dev

if the above commands didn't work then go for the below one

sudo apt install libgconf-2-4 libatk1.0-0 libatk-bridge2.0-0 libgdk-pixbuf2.0-0 libgtk-3-0 libgbm-dev libnss3-dev libxss-dev

Abhijay007j
  • 888
  • 6
  • 13
  • 4
    Good call. On WSL, need to run apt update first or it won't find the libs. – a5af Jul 26 '21 at 12:27
  • 2
    Note that it's 2021 and this step worked for me in installing puppeteer.js in Ubuntu 20 – Mauvis Ledford Oct 21 '21 at 03:22
  • 1
    This worked for me too on Ubuntu (WSL2) though I didn’t need any of the `-dev` versions (those would be required for building chromium, not simply running it). – Raphael Schweikert Nov 10 '21 at 19:17
  • 1
    Installing `libnss3` on Debian Buster was enough for me to get the file `libnss3.so`. – gekkedev Jan 25 '22 at 11:00
  • 2
    Hi! I have the same problem with `libnss3.so`. BUT! I got it while running wdio automated tests inside of Docker container. I cannot run `update`, `install` or any other command that makes changes to container (don't have rights to modify the container). How can I make Chrome running? Any advice will be much appreciated! – overdd Apr 29 '22 at 20:49
  • On Open suse, the package is `mozilla-nss` – ademar111190 Aug 31 '23 at 14:38
11

When you see this kind of thing, it means your OS is missing low-level libraries that are expected.

To resolve this (Debian/Ubuntu example),

  1. Make sure your package index is up-to-date.
sudo apt update -y
  1. Search the package manager's packages for the one that is missing
apt search libnss3
  1. Determine a suitable candidate from the search results
Sorting... Done
Full Text Search... Done
libnss3/oldstable,now 2:3.42.1-1+deb10u5 amd64
  Network Security Service libraries

libnss3-dev/oldstable 2:3.42.1-1+deb10u5 amd64
  Development files for the Network Security Service libraries

libnss3-tools/oldstable 2:3.42.1-1+deb10u5 amd64
  Network Security Service tools

nss-passwords/oldstable 0.2-2+b2 amd64
  read passwords from a Mozilla keyring
  1. Install the candidate
sudo apt install -y libnss3
  1. Run your command again

If the error message goes away => success

If the error message changes => repeat for the new error message

If the error message does not change => the library you installed didn't have the files you need, so uninstall and try a different one

# Uninstall the package and delete its configuration files
sudo apt purge -y libnss3
# Uninstall dangling dependencies
sudo apt autoremove -y

See also man apt-get

Ders
  • 1,068
  • 13
  • 16
  • Did not work for me with wsl2 unfortunately. Thanks anyways – Kevin Connors Apr 05 '22 at 20:44
  • 1
    Purging libnss3 took a hell of a lot of software with it. Basically everything written in Java... Would not recommend. – Lori Aug 29 '22 at 14:20
  • Hi, I am also facing same while running on Jenkins ci/CD and my repo on gitlab. Can you please let me know where I need to install libnss3.so and where I need to run sudo apt install -y libnss3....? – AutomationWorld Mar 10 '23 at 12:02
  • Thank you for your well explained answer – Giovanne Afonso May 16 '23 at 20:02
  • @Lori I think you are mistaken. The only difference between `purge` and `remove` is that `purge` also deletes configuration files; neither have the ability to uninstall other unspecified packages. Maybe you also ran `autoremove` and other software was uninstalled. This is as expected especially if you haven't run it before, since the purpose of it is to remove dangling dependencies. Please refer to the man page [`man apt-get`](https://manpages.ubuntu.com/manpages/xenial/man8/apt-get.8.html) if you have any questions. I will add brief comment on those lines for people who may be less familiar. – Ders May 28 '23 at 20:06
4

You need to satisfy the libraries dependencies to run chrome in a headless mode:

sudo apt-get update && sudo apt-get 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 libnss3 lsb-release xdg-utils wget ca-certificates

For more

Deividson Calixto
  • 350
  • 1
  • 4
  • 11