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

升级Node.js 20后Puppeteer部署异常:找不到Chrome的解决方案

Puppeteer部署到Jules时找不到Chrome的解决办法

问题背景

将Node.js升级至20版本、Angular升级至15.2.10,并用Puppeteer@^20.9.0替换PhantomJS使用Headless Chrome后,本地运行正常,但部署到Jules时出现错误:

Error: Could not find Chrome (ver. 115.0.5790.98). This can occur if either

  1. you did not perform an installation before running the script (e.g. npm install)
  2. your cache path is incorrectly configured

已尝试执行node node_modules/puppeteer/install.js、下载对应版本ChromeDriver、清理node_modules、设置PUPPETEER_SKIP_DOWNLOAD=true,均未解决问题。

可行解决思路

1. 绑定系统已安装的Chrome

如果Jules服务器上已安装Chrome,直接指定其执行路径即可:

  • 通过环境变量配置:
    export PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome
    
  • 或在代码中硬编码路径(需确认服务器上Chrome的实际路径):
    const puppeteer = require('puppeteer');
    (async () => {
      const browser = await puppeteer.launch({
        executablePath: '/usr/bin/google-chrome',
        headless: 'new' // Puppeteer v20+推荐使用new无头模式
      });
      // 业务逻辑代码
    })();
    

2. 修复缓存路径权限与配置

Puppeteer默认将Chrome缓存到用户目录的.cache/puppeteer,部署进程可能无读写权限:

  • 手动指定可写的缓存目录:
    export PUPPETEER_CACHE_DIR=/opt/puppeteer-cache
    
  • 确保该目录权限正确(比如给运行进程的用户读写权限),然后重新执行npm install触发Chrome下载。

3. 规范部署环境的依赖安装流程

部署时可能未完整执行依赖安装,建议在部署脚本中使用:

npm ci --only=production

npm ci会严格按照package-lock.json安装依赖,避免版本不一致导致的问题。

4. 安装Headless Chrome系统依赖

Jules服务器可能缺少Headless Chrome运行所需的系统库,以Debian/Ubuntu为例:

sudo apt-get install -y libnss3 libatk-bridge2.0-0 libdrm-dev libxkbcommon-dev libgbm-dev libasound-dev libatspi2.0-0 libxshmfence-dev

这些依赖是Chrome无头模式运行的必要组件,缺失会导致启动失败或找不到Chrome。

5. 匹配Puppeteer与Chrome版本

Puppeteer每个版本对应固定的Chrome版本,若服务器上Chrome版本固定,可查询对应关系后调整Puppeteer版本。比如服务器Chrome为114.x,则安装与之兼容的Puppeteer版本,避免版本不匹配。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 13:45:07