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

如何在Replit中运行whatsapp-web.js?解决依赖库安装问题

在Replit中运行whatsapp-web.js的解决方案

解决步骤

1. 安装系统依赖

在Replit终端直接执行以下命令(无需sudo),安装Chromium运行所需的全部缺失库:

apt-get update && apt-get install -y libgobject-2.0-0 libglib2.0-0 libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libpango-1.0-0 libcairo2

2. 修改客户端配置

调整Client初始化参数,添加适配Replit环境的Puppeteer启动参数,规避沙箱和资源限制问题:

const qrcode = require('qrcode-terminal');
const { Client, LocalAuth } = require('whatsapp-web.js');

const client = new Client({
    authStrategy: new LocalAuth(),
    puppeteer: {
        args: [
            '--no-sandbox',
            '--disable-setuid-sandbox',
            '--disable-dev-shm-usage',
            '--disable-accelerated-2d-canvas',
            '--no-first-run',
            '--no-zygote',
            '--single-process',
            '--disable-gpu'
        ]
    }
});

client.on('qr', qr => {
    qrcode.generate(qr, { small: true });
});

client.on('ready', () => {
    console.log('Client is ready!');
});

client.on('message', async msg => {
    const text = msg.body.toLowerCase() || '';
    if (text === '!ping') {
        msg.reply('pong');
    }
});

client.initialize();

3. 确认npm依赖完整

执行命令安装所需npm包:

npm install whatsapp-web.js qrcode-terminal

问题说明

Replit默认环境缺少whatsapp-web.js依赖的Chromium浏览器所需底层系统库,错误提示的libgobject-2.0.so.0正是其中之一。Replit限制sudo使用,但直接通过apt-get即可无权限限制安装依赖。另外添加Puppeteer启动参数是为了适配Replit无头环境,避免沙箱机制和资源不足导致的浏览器启动失败。

内容的提问来源于stack exchange,提问作者M. Al lail Qadrillah

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 13:25:15