人偶错误:未下载Chromium版本

Mos*_*rtz 3 chromium node.js npm puppeteer

npm i puppeteer按照文档中的说明使用, 但出现以下错误:

(节点:2066)UnhandledPromiseRejectionWarning:错误:未下载Chromium版本。在Launcher.launch中运行“ npm install”或“ yarn install”

当我尝试这个例子(也从文档):

const puppeteer = require('puppeteer');
(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({path: 'example.png'});
  await browser.close();
})();
Run Code Online (Sandbox Code Playgroud)

同样在文档中:

注意:安装Puppeteer时,它会下载Chromium的最新版本(〜170MB Mac,〜282MB Linux,〜280MB Win),保证可以使用该API。

任何帮助,将不胜感激。

Afs*_*azi 87

经过大量搜索和尝试大部分建议后,我只能通过手动安装 Chromium 来解决该问题:

node node_modules/puppeteer/install.js
Run Code Online (Sandbox Code Playgroud)

  • 我的本地模块有“puppeteer-core”而不是“puppeteer”,但解决方案的工作原理相同。 (2认同)

Phi*_*ßen 27

默认情况下,puppeteer模块将运行其安装脚本 ( node install.js)。但是,就我而言,我ignore-scripts=true在我的~/.npmrc文件中启用了它,所以它从未执行过。

在这种情况下,您必须自己运行命令:

node node_modules/puppeteer/install.js
Run Code Online (Sandbox Code Playgroud)

检查:node_modules/puppeteer/.local-chromium/linux-<your_chrome_version>/现在应该存在。


小智 10

对于Linux:

1- 您必须使用以下命令安装了 Chrome 浏览器:

$sudo apt install -y 铬浏览器

2-您必须使用以下命令获取铬的可执行路径:

$which 铬浏览器

3-将可执行路径作为启动函数的参数:

   const puppeteer = require('puppeteer-core');
   (async () => {
   const browser = await puppeteer.launch({
   executablePath: '/usr/bin/chromium-browser',
   headless: false
    });
    const page = await browser.newPage();
    await page.goto('https://google.com');
    await page.screenshot({path: 'example.png'});

    await browser.close();
    })();
Run Code Online (Sandbox Code Playgroud)


Mos*_*rtz 9

经过多次尝试,我终于在这里找到了答案:

sudo npm install puppeteer --unsafe-perm=true --allow-root
Run Code Online (Sandbox Code Playgroud)

正如@vsync指出的那样,这仅适用于linux

  • 这个答案是专门针对Linux的,这使得它对许多开发人员来说毫无用处,因为Windows操作系统仍然占据主导地位 (2认同)
  • 但是用于Windows的ubuntu bash才是有用的 (2认同)

f1v*_*lad 6

确认这里提供的解决方案几乎可以工作。这是我的设置。16.

从命令行安装 Chrome 浏览器,然后:

    const browser = await puppeteer.launch({
        executablePath: "/usr/bin/chromium-browser",
        args: ['--no-sandbox']
    });
Run Code Online (Sandbox Code Playgroud)


Vik*_*pta 5

就我而言,删除 node_modules 文件夹和 package-lock.json 文件并再次运行 npm install 后它就起作用了。