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.


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


# Build the application

RUN yarn build

# Run the web service on container startup.

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


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:
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?


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