DEV Community

Terry W
Terry W

Posted on

Fixing Playwright build errors on Render when browsers are missing

TL;DR

If Playwright runs locally but fails on Render with "executable does not exist", install Chromium during build and set PLAYWRIGHT_BROWSERS_PATH to a folder inside the project so the browser binary is included in the deploy artifact.

Background

I am using Playwright on my API to render email templates for my app, Snap Template. It works fine on my computer (insert meme here), but after deploying to Render the export feature failed with Playwright complaining the Chromium executable did not exist. This post explains how I diagnosed the issue and the fix I used so Playwright can find the browser binary in the deployed service.

Render deploy log with Playwright executable not found error

Root cause

  • Locally I had previously run npx playwright install, so the browser binaries existed in my local cache.
  • The runtime container therefore did not have the Chromium binary at the expected path and Playwright failed to launch it.

The working fix

  1. Add a postinstall script to package.json that installs Chromium only: "postinstall": "npx playwright install chromium"
  2. Use this build command on Render so the postinstall runs during build: npm install && npm run postinstall && npm run build
  3. Add this environment variable in Render, pointing to the path for the playwright cache inside the built project: PLAYWRIGHT_BROWSERS_PATH=/opt/render/project/.cache/playwright

package.json scripts section showing postinstall entry

Render environment variables page showing PLAYWRIGHT_BROWSERS_PATH set

Render deploy log showing successful deploy and export run

Why this works

  • postinstall downloads Chromium into the project when the build runs.
  • PLAYWRIGHT_BROWSERS_PATH forces Playwright to put and look for the browser binaries in a folder that is part of the deployed artifact. The runtime process finds the executable and Playwright launches correctly.

Extra Checks and Good Practices

  • Monitor disk usage. Playwright browser files are large. Keep an eye on Render storage and logs.
  • Consider playwright-chromium if you want a smaller install that targets Chromium only.
  • If you need guaranteed system libraries and reproducible builds, use a Playwright-ready Docker image such as mcr.microsoft.com/playwright:latest. That image includes OS deps and browser binaries.
  • Add a tiny startup debug log for chromium.executablePath() to aid future diagnostics.
  • Do the Playwright install during build only. Installing at runtime increases cold start time.

TLDR checklist

  • Did postinstall run during build? Check Render build logs.
  • Is PLAYWRIGHT_BROWSERS_PATH pointing inside the project? If not, set it.

Closing notes

If you deploy Playwright on a host that separates build and runtime you will likely need to install the browsers into the deploy artifact. Setting the Playwright browsers path to a project folder in the environment variables and running npx playwright install chromium during build solved this for me on Render.

If this helped you do the Playw-right thing and get your service working, or you have a cleaner approach, drop a comment. I’m running SnapTemplate and would love to hear how you use Playwright in your app.

Top comments (0)