Puppeteer Setup in pnpm Monorepo (Ubuntu)
Root Cause (common issues)
- Puppeteer not installed →
npx puppeteercommand not found - Chrome never downloaded → path missing
- pnpm monorepo skips
postinstallscripts (no auto browser download)
Step 1: Install Puppeteer
From the repo root (workspace-wide):
bash
pnpm add -w puppeteerOr scoped to a specific app only:
bash
pnpm add puppeteer --filter @my-app/backendStep 2: Install Chrome (pnpm way — don't use npx)
bash
pnpm exec puppeteer browsers install chromeFallback if above fails:
bash
pnpm dlx puppeteer browsers install chromeForce re-install (useful in CI or after pnpm install):
bash
pnpm exec puppeteer browsers install chrome --forceStep 3: Verify
bash
ls ~/.cache/puppeteer/chrome/
ldd ~/.cache/puppeteer/chrome/linux-*/chrome-linux64/chrome | grep "not found"
# Should print nothing if all libs are presentStep 4: Install Ubuntu System Libraries
Ubuntu 22.04
bash
sudo apt-get install -y \
libnspr4 libnss3 libasound2 \
libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 \
libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 \
libxrandr2 libgbm1 libpango-1.0-0 libcairo2 \
libatspi2.0-0 libxshmfence1Ubuntu 24.04 (libasound2 renamed to libasound2t64)
bash
sudo apt-get update
sudo apt-get install -y \
libnspr4 libnss3 libasound2t64 \
libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 \
libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 \
libxrandr2 libgbm1 libpango-1.0-0 libcairo2 \
libatspi2.0-0 libxshmfence1Step 5: Runtime Config (required on EC2 / servers)
Always launch with sandbox disabled in server environments:
js
puppeteer.launch({
headless: 'new',
args: ['--no-sandbox', '--disable-setuid-sandbox'],
})One-Shot Fix (copy-paste)
bash
# Install puppeteer in workspace
pnpm add -w puppeteer
# Install Chrome
pnpm exec puppeteer browsers install chrome
# Install Ubuntu 24.04 system deps
sudo apt-get update
sudo apt-get update
sudo apt-get install -y \
libnspr4 libnss3 libasound2t64 \
libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 \
libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 \
libxrandr2 libgbm1 libpango-1.0-0 libcairo2 \
libatspi2.0-0 libxshmfence1Turborepo Gotcha
pnpm in monorepos often skips postinstall scripts (especially in CI), so Chrome is never auto-downloaded after pnpm install. Always run the browser install step explicitly after deploying or setting up a new environment.
