Docker: puppeteer not working on a Express (NestJS) app

Hey team,
I’m trying to run puppeteer and it seems like there are some issues with spawning the browser.

Docker file:


# Use the official lightweight Node.js 12 image.

# https://hub.docker.com/_/node

FROM node:14-alpine

# Create and change to the app directory.

WORKDIR /usr/src/app

# Copy application dependency manifests to the container image.

# A wildcard is used to ensure both package.json AND package-lock.json are copied.

# Copying this separately prevents re-running npm install on every code change.

COPY package*.json ./

# Install dependencies

RUN yarn

# Copy local code to the container image.

COPY . ./

# Expose the port

EXPOSE 80

# Build the application

RUN yarn build

# Run the web service on container startup.

CMD [ "yarn", "start:prod" ]

Task:

const browser = await puppeteer.launch({ args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-dev-shm-usage", "--disable-extensions"] });
    try {
      const page = await browser.newPage();
      await page.setContent(`<p>This is but an example</p>`});
      await page.addStyleTag({ path: this.config.css() })
      await page.evaluateHandle(EVALUATE_FONTS); // wait for fonts loading
     (...)

It breaks on launching the puppeteer browser instance, here’s the look:

Error: Failed to launch the browser process! spawn /usr/src/app/node_modules/puppeteer/.local-chromium/linux-901912/chrome-linux/chrome ENOENT
Nov 19 08:29:11 PM  TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
Nov 19 08:29:11 PM  
Nov 19 08:29:11 PM      at onClose (/usr/src/app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:197:20)
Nov 19 08:29:11 PM      at ChildProcess.<anonymous> (/usr/src/app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:189:85)
Nov 19 08:29:11 PM      at ChildProcess.emit (events.js:400:28)
Nov 19 08:29:11 PM      at ChildProcess.emit (domain.js:475:12)
Nov 19 08:29:11 PM      at Process.ChildProcess._handle.onexit (internal/child_process.js:280:12)
Nov 19 08:29:11 PM      at onErrorNT (internal/child_process.js:469:16)
Nov 19 08:29:11 PM      at processTicksAndRejections (internal/process/task_queues.js:82:21)

FYI: It works fine on local (same docker) and Heroku. I’m no expert but it looks like there’s some deps missing

Hi @joaquimley, sorry for the late reply here. We’re happy to take a closer look - can you let us know the name of the service you’re seeing this issue on?

Thanks!

Hello @Jade_Paoletta, no worries. Do you mean my service on render? If so:

Thanks @joaquimley, from the error you provided, it sounds like it’s not able to find the chromium executable at that path. There may be some issues with the embedded version of chromium that puppeteer provides. Some other folks that have run into this error seem to have had success by running chromium from /usr/bin/chromium-browser instead of the default path that puppeteer provides - that may be worth a shot. I found this thread to be helpful: Error: Failed to launch chrome! spawn /app/node_modules/puppeteer/.local-chromium/linux-609904/chrome-linux/chrome ENOENT · Issue #3994 · puppeteer/puppeteer · GitHub

1 Like

Hello Jade,

Thank you so much for providing the thread and therefore the solution, it worked! :wink:

1 Like

@jade_paoletta would Render consider making it more zero-config to use Puppeteer v19+ on Render.com?

Right now it’s a bit of a footgun when Puppeteer is deployed out of the box without configuration - the default installation path $HOME/.cache/puppeteer does not get copied to the production environment on Render, leading to confusing errors.

Would the Render team consider copying $HOME/.cache to the production environment by default? (or better said: not discarding it between build environment and production environment?) Keeping this directory seems like a behavior that is mirrored by other deployment / CI environments.

We can also submit a separate Render Community discussion about this, but it would be great if Render would consider this change.

1 Like