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

Node Puppeteer出现yargs模块缺失报错,已尝试多种方法仍未解决求助

解决Puppeteer找不到yargs模块的方案
  • 强制重新安装指定版本的@puppeteer/browsers
    报错指向该包的子依赖缺失,直接针对它重新安装匹配版本:
    npm install --force @puppeteer/browsers@1.4.1(此版本与Puppeteer 19.5.2配套)

  • 启用npm依赖扁平化并重装
    依赖嵌套可能导致路径问题,先设置扁平化:
    npm config set legacy-peer-deps true
    然后清理依赖文件并重装:

    # Windows系统
    rmdir /s /q node_modules && del package-lock.json
    # macOS/Linux系统
    rm -rf node_modules package-lock.json
    npm install
    
  • 手动在根依赖中锁定yargs版本
    在package.json的dependencies中添加:

    "yargs": "17.7.2"
    

    执行npm install,让yargs安装在根目录node_modules,确保子依赖能读取到。

  • 彻底清除包管理器缓存
    除了npm缓存,若使用其他包管理器也需清理:

    # npm
    npm cache clean --force
    # yarn(若使用)
    yarn cache clean
    # pnpm(若使用)
    pnpm store prune
    
  • 回退到完全匹配的版本组合重装
    若升级版本无效,回到原版本并确保所有依赖版本对齐:

    rm -rf node_modules package-lock.json
    npm install puppeteer@19.5.2 puppeteer-core@19.5.2 @puppeteer/browsers@1.4.1 yargs@17.7.2
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 07:45:01