Node.js 错误:无法启动浏览器,错误消息:无法启动浏览器进程

Node.js 错误:无法启动浏览器,错误消息:无法启动浏览器进程,node.js,discord.js,Node.js,Discord.js,我正在Replit中托管我的Discord Bot。并且,我使用nodehtml-to-image包将html转换为jpeg。当我在本地主机上尝试时,它工作得非常好。但当我在Replit中尝试时,它返回以下错误: (node:250) UnhandledPromiseRejectionWarning: Error: Unable to launch browser, error message: Failed to launch the browser process! 以下是我正在使用的代

我正在Replit中托管我的Discord Bot。并且,我使用nodehtml-to-image包将html转换为jpeg。当我在本地主机上尝试时,它工作得非常好。但当我在Replit中尝试时,它返回以下错误:

(node:250) UnhandledPromiseRejectionWarning: Error: Unable to launch browser, error message: Failed to 
launch the browser process!
以下是我正在使用的代码htmltpng.js:

非常感谢您的帮助!
谢谢

您的目标是创建一张欢迎卡,然后将其发布到一个频道,对吗?为什么不使用canvas呢?它更快、更高效?网上甚至有专门针对不和谐的指南:

快乐编码

发行 包节点html-to-image当前使用的是pupeteer 3.0.0,它不包括所有必要的依赖项。这在pupeteer 3.0.4中是固定的

解决方案 您可以在等待软件包更新时安装必要的依赖项

sudo apt get安装-y libgbm dev

链接 下面是节点html到图像的问题


这是Pupeter方面的问题

谢谢!但我也有其他用途。事情的一致性是不容易的。我想使用html/csscombination@AjitKumarcanvas使用类似的CSS样式规则。为这项任务使用浏览器太过分了。如果你想预览一个网页并在discord中显示,你可以使用谷歌的API来实现。如果你想在家里做,试着用sudo运行你的节点进程,也许这个进程就能启动。你能帮我做这个sudo进程吗?@AjitKumar just do sudo nodejs yourproject.jsI试过了,但它给出了这个错误:sh:1:sudo:not found exit status 127有帮助吗?我看到了,但它也不起作用!请参阅更新的问题/代码虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能无效。-@卡米尔很抱歉这么懒这看起来更好吗?
const { MessageAttachment } = require("discord.js");
const nodeHtmlToImage = require("node-html-to-image");

const puppeteer = { args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-accelerated-2d-canvas', '--no-first-run', '--headless', '--no-zygote', '--disable-gpu'], headless: true, ignoreHTTPSErrors: true };

module.exports = async (msg, user, data) => {
  const _htmlTemplate = `<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <style>
      body {
        font-family: "Poppins", Arial, Helvetica, sans-serif;
        background: rgb(22, 22, 22);
        color: #fff;
        max-width: 300px;
      }

      .app {
        max-width: 300px;
        padding: 20px;
        display: flex;
        flex-direction: row;
        border-top: 3px solid rgb(16, 180, 209);
        background: rgb(31, 31, 31);
        align-items: center;
      }

      img {
        width: 50px;
        height: 50px;
        margin-right: 20px;
        border-radius: 50%;
        border: 1px solid #fff;
        padding: 5px;
      }
    </style>
  </head>
  <body>
    <div class="app">
      <img src="${user.username}" />

      <h4>Welcome ${msg.author.username}</h4>
    </div>
  </body>
</html>
`;

  const images = await nodeHtmlToImage({
    html: _htmlTemplate,
    quality: 100,
    type: "jpeg",
    puppeteerArgs: puppeteer,
  });

  return msg.channel.send(new MessageAttachment(images, `${name}.jpeg`));
};