/tmp/chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory Vercel

I had the same issue where puppeteer was running okay on my local environment but when i deployed to AWS EC2 i face up the same error shared loading libraries
Solution

  1. First check the version of nodejs you are running and if its not less than v14.0 or greater than v14.0. Upgrade or downgrade (recommended to upgrade) and restart your app then try.

The most common cause is a bug in Node.js v14.0.0 which broke extract-zip, the module Puppeteer uses to extract browser downloads into the right place. The bug was fixed in Node.js v14.1.0, so please make sure you’re running that version or higher. Alternatively, if you cannot upgrade, you could downgrade to Node.js v12, but we recommend upgrading when possible.

  1. Trivial:- Make sure the directory where your project folder is located is not owned by root.

For those who might have experience this issue while running on windows enviroment, You can try to pass ignoreDefaultArgs: [‘–disable-extensions’] option when launching it chromium from code i.e

const browser = await puppeteer.launch({ignoreDefaultArgs: ['--disable-extensions']})

This will deactivate default behaviour of puppeteer from disabling any extensions usually used by chromium/chrome.

Linux and MAcOS uses

The issues that results in this error

UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory TROUBLESHOOTING

is mostly but not all the times caused by missing dependencies that are required in the latest version. The good thing is you can easily check the missing chrome dependencies causing the crash.

  • Make sure you are in the root folder of your project
  • Navigate to node_modules folder
  • Navigate to the folder where puppeteer chrome Linux tools are installed
  • cd /project_folder/node_modules/puppeteer/.local-chromium/linux-some number/chrome-linux
    replace the linux-some number with whatever ls will output
  • ls at /.local-chromium to check name of your directory
  • At the last directory [ chrome-linux ] run below command to check the missing dependencies

    ldd chrome | grep not

if you see any missing dependencies, run this command to install everything and restart your application.

sudo apt-get install ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 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 lsb-release wget xdg-utils

Voila!! everything should be fixed

Leave a Comment

tech