Skip to content

Commit 0d4a3af

Browse files
committed
Install puppeteer Chrome explicitly in Netlify build
The docs build screenshots examples with puppeteer, which needs a Chrome binary. Puppeteer downloads it in a postinstall hook, but Netlify caches node_modules and skips postinstall when the lockfile is unchanged, so Chrome was missing on most builds ("Could not find Chrome"). Install chrome-headless-shell explicitly before building, and persist it via a repo-local PUPPETEER_CACHE_DIR that netlify-plugin-cache restores across deploys.
1 parent 32e9bdd commit 0d4a3af

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ tests/VerifyExamples
44
.DS_Store
55
node_modules/
66
build/
7+
.puppeteer-cache/
78
*.swp
89
.idea

netlify.toml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,28 @@
77
# directory between builds with netlify-plugin-cache.
88

99
[build]
10-
command = "npm run build-docs"
10+
# The publisher screenshots examples with puppeteer, which needs a Chrome
11+
# binary. Puppeteer normally downloads it in a postinstall hook, but Netlify
12+
# caches node_modules: when the lockfile is unchanged npm reports "up to date"
13+
# and skips postinstall, so Chrome never lands. We install it explicitly here
14+
# (a no-op once it's in the cached PUPPETEER_CACHE_DIR below) before building.
15+
# The publisher launches with headless: "shell", so chrome-headless-shell is
16+
# the binary it actually needs.
17+
command = "npx puppeteer browsers install chrome-headless-shell && npm run build-docs"
1118
publish = "build"
1219

1320
[build.environment]
1421
# The publisher requires Node 22+ (it also reads .nvmrc).
1522
NODE_VERSION = "22.20.0"
23+
# Put puppeteer's browser download inside the repo so netlify-plugin-cache can
24+
# persist it (the default ~/.cache/puppeteer is outside the cached paths).
25+
PUPPETEER_CACHE_DIR = "/opt/build/repo/.puppeteer-cache"
1626

17-
# Restore build/ before the build and save it afterwards, so the incremental
18-
# cache and prior outputs survive across deploys.
27+
# Restore build/ and the puppeteer browser cache before the build and save them
28+
# afterwards, so the incremental cache, prior outputs, and Chrome all survive
29+
# across deploys.
1930
[[plugins]]
2031
package = "netlify-plugin-cache"
2132

2233
[plugins.inputs]
23-
paths = ["build"]
34+
paths = ["build", ".puppeteer-cache"]

0 commit comments

Comments
 (0)