【问题标题】:Error: Could not find browser revision 756035. Run "npm install"错误:找不到浏览器修订版 756035。运行“npm install”
【发布时间】:2020-10-30 09:16:36
【问题描述】:

我的代码如下:

 const browser = await puppeteer.launch({headless: params["headless"]});

 
    const page = await browser.newPage();
    await page.setJavaScriptEnabled(true);
    await page.setRequestInterception(true);
...

问题是我无法运行它。我收到以下异常。

(node:7008) UnhandledPromiseRejectionWarning: Error: Could not find browser revision 756035. Run "npm install" or "yarn install" to download a browser binary.
    at ChromeLauncher.launch (C:\Users\rpaadmin\.jenkins\workspace\ikinciyeni\generic_scrapper\node_modules\puppeteer\lib\Launcher.js:59:23)
    at async browse (C:\Users\rpaadmin\.jenkins\workspace\ikinciyeni\generic_scrapper\main_2.0_temp.js:126:19)
    at async tryExecute (C:\Users\rpaadmin\.jenkins\workspace\ikinciyeni\generic_scrapper\main_2.0_temp.js:73:5)
    at async sequentialFor (C:\Users\rpaadmin\.jenkins\workspace\ikinciyeni\generic_scrapper\main_2.0_temp.js:416:5)
    at async tryExecute (C:\Users\rpaadmin\.jenkins\workspace\ikinciyeni\generic_scrapper\main_2.0_temp.js:60:5)
    at async sequentialFor (C:\Users\rpaadmin\.jenkins\workspace\ikinciyeni\generic_scrapper\main_2.0_temp.js:416:5)
    at async tryExecute (C:\Users\rpaadmin\.jenkins\workspace\ikinciyeni\generic_scrapper\main_2.0_temp.js:60:5)
    at async httpBlock (C:\Users\rpaadmin\.jenkins\workspace\ikinciyeni\generic_scrapper\main_2.0_temp.js:268:5)
    at async tryExecute (C:\Users\rpaadmin\.jenkins\workspace\ikinciyeni\generic_scrapper\main_2.0_temp.js:64:5)
    at async sequentialFor (C:\Users\rpaadmin\.jenkins\workspace\ikinciyeni\generic_scrapper\main_2.0_temp.js:416:5)
(node:7008) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

我该如何解决?它以前工作得很好。

【问题讨论】:

  • 你运行npm install的上下文是什么?例如,您使用的是管理员权限还是 WSL?
  • @Seblor 为听起来很奇怪而道歉,但我也不知道。你是指管理员还是用户?
  • 如果您以管理员权限运行npm install,但尝试在没有这些权限的情况下启动,则可能是权限问题。
  • 这是权限问题。我收到此错误 npm ERR!该操作被您的操作系统拒绝。 npm 错误!该文件可能已被使用(由文本编辑器或防病毒软件),npm ERR!或者您没有访问它的权限。 npm 错误! npm 错误!如果您认为这可能是权限问题,请仔细检查 npm ERR!文件及其包含目录的权限,或尝试运行 npm ERR!再次以 root/Administrator 身份执行该命令。
  • 当我尝试重新安装它时会发生这种情况@Seblor

标签: node.js puppeteer


【解决方案1】:

如果其他人遇到类似问题,请删除节点模块文件夹并再次运行。它会工作

【讨论】:

  • 删除节点模块很昂贵,请参阅下面来自 Андрей Мархай 的答案以安装 puppeteer。
【解决方案2】:

为了将来的参考,我必须执行以下操作才能使其在我的 ubuntu 服务器上运行(启动 Chrome):

  1. 指向您的本地 chromium(启动选项 - 可执行路径,在我的例子中:node_modules/puppeteer/.local-chromium/linux-809590/chrome-linux/chrome')

  2. 更新你的包:

sudo apt-get install libpangocairo-1.0-0 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxi6 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libgconf2-4 libasound2 libatk1.0-0 libgtk-3-0

  1. 添加那个偷偷摸摸的包:

sudo apt-get install -y libgbm-dev

【讨论】:

    【解决方案3】:

    无需删除所有 node_modules 文件夹

    运行 npm i puppeteer 它将更新您对铬的修订

    【讨论】:

      【解决方案4】:

      如果上述任何解决方案都不起作用,就我而言(在 digitalocean 液滴上的 ubuntu 16.04.3 LTS 上运行)导致此错误是因为 npm 拒绝安装 chromium 作为 puppeteer 的依赖项。我不知道这种行为的原因,但我在其他地方看到过它的报道。我使用的是完整版的 puppeteer,而不是 puppeteer-core。

      对我有用的是通过 npm 手动安装 chromium:

      npm install chromium
      

      然后在我的 puppeteer 脚本中,显式设置可执行文件:

      puppeteer.launch({
        executablePath: './node_modules/chromium/lib/chromium/chrome-linux/chrome',
        // be sure to verify that this path matches your installation, but this is where npm put it in my node_modules directory
        // and of course include any other launch arguments you need here
      });
      

      但我很想知道是否有比这更好的解决方案。

      【讨论】:

        猜你喜欢
        • 2020-05-12
        • 2020-11-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-07
        • 2019-10-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多