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

CentOS 7下npm安装Puppeteer报错:找不到install.js模块

解决CentOS 7安装Puppeteer@19.4.1的报错问题

修复步骤

1. 清理缓存后重新安装

缓存损坏会导致依赖下载不完整,执行以下命令重置安装环境:

npm cache clean --force
rm -rf node_modules package-lock.json
npm i puppeteer@19.4.1

2. 指定国内镜像源下载Chrome

CentOS 7常因网络问题无法访问谷歌服务器,导致Chrome下载失败触发脚本错误,通过环境变量切换国内镜像:

PUPPETEER_DOWNLOAD_HOST=https://npm.taobao.org/mirrors npm i puppeteer@19.4.1

3. 升级Node.js到兼容版本

Puppeteer@19.4.1要求Node.js版本≥14.14.0,CentOS 7默认版本偏低,需升级:

  1. 卸载系统自带的Node.js和npm:
sudo yum remove nodejs npm -y
  1. 添加NodeSource的16.x版本源:
sudo tee /etc/yum.repos.d/nodesource.repo <<EOF
[nodesource]
name=Node.js Packages for Enterprise Linux 7 - \$basearch
baseurl=https://rpm.nodesource.com/pub_16.x/el/7/\$basearch
enabled=1
gpgcheck=1
gpgkey=https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL
EOF
  1. 安装Node.js:
sudo yum install nodejs -y
  1. 验证版本:node -v,确认显示v16.x.x后,重新执行npm i puppeteer@19.4.1

4. 修复npm权限问题

权限不足会导致依赖无法写入node_modules目录,执行以下命令修复:

sudo chown -R $USER:$USER ~/.npm
npm i puppeteer@19.4.1

5. 手动执行安装脚本

如果以上方法无效,跳过自动脚本先下载依赖,再手动触发Chrome安装:

# 下载Puppeteer包但跳过postinstall脚本
npm i puppeteer@19.4.1 --ignore-scripts
# 进入Puppeteer目录执行安装脚本
cd node_modules/puppeteer
node install.js

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 18:05:31