You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Render部署Puppeteer报错:无法找到Chrome(版本121.0.6167.85)

解决Render部署后Puppeteer无法找到Chrome生成PDF的问题

问题分析

报错显示Puppeteer无法定位到指定版本的Chrome(121.0.6167.85),核心原因是Render默认运行环境未预装对应版本的Chrome,或是Puppeteer的缓存路径存在权限/配置异常。

解决方案

1. 安装Chrome系统依赖包

Render基于Ubuntu环境,需先安装Chrome运行必需的系统依赖。可在项目的build.sh脚本或Render的构建命令中添加:

sudo apt-get update && sudo apt-get install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libasound2 libpangocairo-1.0-0

2. 调整Puppeteer包与安装配置

  • 若当前使用puppeteer-core,建议切换为完整的puppeteer包,它会自动管理Chrome的安装流程:
    npm uninstall puppeteer-core && npm install puppeteer
    
  • 在package.json中添加postinstall脚本,确保部署阶段自动安装Chrome:
    "scripts": {
      "postinstall": "npx puppeteer browsers install chrome"
    }
    

3. 修正缓存路径权限问题

Render默认的/opt/render/.cache/puppeteer可能存在权限限制,可将缓存路径指定到项目目录内:

  • 方式一:通过环境变量配置
    在Render项目的环境变量中添加:
PUPPETEER_CACHE_DIR=./.puppeteer_cache
  • 方式二:通过代码直接设置
    在Puppeteer启动前添加配置项:
const puppeteer = require('puppeteer');

const browser = await puppeteer.launch({
  cacheDirectory: './.puppeteer_cache',
  headless: 'new',
  args: ['--no-sandbox', '--disable-setuid-sandbox']
});

4. 直接调用系统预装Chrome

若不想通过Puppeteer安装Chrome,可直接使用Render环境中预装的Chromium。先通过命令确认路径:

which chromium-browser

通常路径为/usr/bin/chromium-browser,随后在代码中指定该路径:

const browser = await puppeteer.launch({
  executablePath: '/usr/bin/chromium-browser',
  headless: 'new',
  args: ['--no-sandbox', '--disable-setuid-sandbox']
});

验证部署

修改完成后重新部署至Render,检查构建日志是否出现Chrome安装成功的提示,再测试PDF生成接口功能。

内容的提问来源于stack exchange,提问作者user23666822

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 13:10:00