npm global installation of Puppeteer fails with error code 1 on Ubuntu

I’m having trouble installing Puppeteer as a global package on my Ubuntu 20.04 system. When I run the installation command, it fails with an error.

Here’s what I tried:

npm install -g puppeteer

The installation process stops and shows this error:

npm ERR! code 1
npm ERR! path /usr/local/lib/node_modules/puppeteer
npm ERR! command failed
npm ERR! command sh -c node install.mjs
npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-05-03T19_37_45_119Z-debug-0.log

I’m running Node.js version v18.20.2 and npm version 10.5.0. The error seems to happen during the post-install script execution. Has anyone encountered this issue before? What might be causing this installation failure?

Had this exact issue last month setting up CI. The problem was running out of disk space when downloading Chromium. Run df -h to check your storage first. Global installs can also mess things up because of npm cache corruption. Try npm cache clean --force then reinstall. What worked for me was using puppeteer-core instead - it doesn’t bundle Chromium, so you just point it to your system Chrome. Also make sure your connection’s stable since the Chromium download is huge and can timeout on slow networks.

This issue often arises when Puppeteer attempts to download Chromium and encounters permission problems or missing dependencies. I faced a similar problem on Ubuntu 18.04. Initially, try running the command with sudo. If that doesn’t resolve the issue, ensure you have the following system dependencies installed: libx11-xcb1, libxcomposite1, libxcursor1, libxdamage1, libxi6, libxtst6, libnss3, libcups2, libxss1, libxrandr2, libasound2, libpangocairo-1.0-0, and libgtk-3-0. Alternatively, you can bypass the Chromium download by setting PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true before installation, allowing you to manage the browser setup manually later. The error code 1 indicates that the install.mjs script failed during the Chromium download process.

check your ram too - puppeteer’s install eats memory. i hit the same errors on a 1gb vps until i added swap space. try installing locally first with npm install puppeteer to see if it’s a global install issue or the package itself.