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

在Vercel部署WhatsApp Bot时遭遇浏览器进程启动失败错误

WhatsApp Bot部署Vercel报错:浏览器进程启动失败

核心错误信息

Error: Failed to launch the browser process!
[0212/144729.058867:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported.

完整部署日志

Running build in Washington, D.C., USA (East) – iad1
Cloning github.com/hritik2002/GitaGpt-Bot (Branch: main, Commit: 17356f1)
Previous build cache not available
Cloning completed: 401.653ms
Running "vercel build"
Vercel CLI 28.15.3
Running "install" command: `npm install`...
npm WARN deprecated puppeteer@13.7.0: < 18.1.0 is no longer supported
added 121 packages, and audited 122 packages in 6s
10 packages are looking for funding
  run `npm fund` for details
found 0 vulnerabilities
/vercel/path0/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:241
            reject(new Error([
                   ^
Error: Failed to launch the browser process!
[0212/144729.058867:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
    at onClose (/vercel/path0/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:241:20)
    at Interface.<anonymous> (/vercel/path0/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:231:68)
    at Interface.emit (node:events:525:35)
    at Interface.close (node:internal/readline/interface:536:10)
    at Socket.onend (node:internal/readline/interface:262:10)
    at Socket.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Node.js v18.12.1
Error: Command "node app.js" exited with 1

项目配置文件(package.json)

{
  "dependencies": {
    "axios": "^0.26.1",
    "qrcode-terminal": "^0.12.0",
    "whatsapp-web.js": "^1.18.0"
  }
}

核心代码(app.js)

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


async function QueryMessage(message) {
  // performs certain task:
}

const client = new Client({
  authStrategy: new LocalAuth(),
});

client.initialize();

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

client.on("authenticated", () => {
  console.log("AUTHENTICATED");
});

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

const sendMessage = async (chat, message) => {
  await chat.sendMessage(await QueryMessage(message));
};

//Replying Messages with image from url
client.on("message", async (message) => {
  const chat = await message.getChat();

  if (!chat.isGroup) {
    sendMessage(chat, message.body);
  }
});

解决方法

  • 问题本质:Vercel以root用户运行进程,而puppeteer默认禁止root用户在未开启--no-sandbox参数的情况下启动浏览器
  • 修改客户端配置,添加puppeteer启动参数:
    const client = new Client({
      authStrategy: new LocalAuth(),
      puppeteer: {
        args: ['--no-sandbox', '--disable-setuid-sandbox']
      }
    });
    
  • 额外提示:Vercel的无服务器环境不支持长期运行的进程(WhatsApp Bot需要持续保持连接),建议改用Railway、Fly.io或传统VPS这类支持常驻进程的平台;若坚持用Vercel,需将Bot改造为API触发模式,但会丢失实时消息接收能力

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 14:25:22