【问题标题】:Lighthouse / Chrome Launcher Error: The environment variable CHROME_PATH must be set to executable of a build of Chromium version 54.0 or laterLighthouse / Chrome Launcher 错误:环境变量 CHROME_PATH 必须设置为 Chromium 版本 54.0 或更高版本的可执行文件
【发布时间】:2021-02-11 01:48:29
【问题描述】:

有人知道是什么导致了这个错误吗?这是 Heroku 日志中显示的错误。它在本地运行良好。

app[web.1]: Generating Lighthouse report...
app[web.1]: An error! ChromePathNotSetError
app[web.1]:     at new LauncherError (/app/node_modules/chrome-launcher/dist/utils.js:37:22)
app[web.1]:     at new ChromePathNotSetError (/app/node_modules/chrome-launcher/dist/utils.js:44:9)
app[web.1]:     at Object.linux (/app/node_modules/chrome-launcher/dist/chrome-finder.js:128:15)
app[web.1]:     at Function.getFirstInstallation (/app/node_modules/chrome-launcher/dist/chrome-launcher.js:131:51)
app[web.1]:     at Launcher.<anonymous> (/app/node_modules/chrome-launcher/dist/chrome-launcher.js:168:47)
app[web.1]:     at Generator.next (<anonymous>)
app[web.1]:     at /app/node_modules/chrome-launcher/dist/chrome-launcher.js:13:71
app[web.1]:     at new Promise (<anonymous>)
app[web.1]:     at __awaiter (/app/node_modules/chrome-launcher/dist/chrome-launcher.js:9:12)
app[web.1]:     at Launcher.launch (/app/node_modules/chrome-launcher/dist/chrome-launcher.js:156:16) {
app[web.1]:   message: 'The environment variable CHROME_PATH must be set to executable of a build of Chromium version 54.0 or later.',
app[web.1]:   code: 'ERR_LAUNCHER_PATH_NOT_SET'
app[web.1]: }

这是我的脚本:

const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');
const express = require('express');
const mobileConfig = require('lighthouse/lighthouse-core/config/lr-mobile-config.js');
const desktopConfig = require('lighthouse/lighthouse-core/config/lr-desktop-config.js');

const app = express();
app.listen(process.env.PORT || 3000, async () => {
  console.log('App listening on port 3000');
  console.log('Generating Lighthouse report...');
  try {
    await generateReport('mobile', mobileConfig);
  } catch(e) {
    console.log('An error!', e);
  }
});


async function generateReport(suffix, config) {

  const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
  const options = {logLevel: 'info', output: 'html', onlyCategories: ['performance'], port: chrome.port };
  const runnerResult = await lighthouse('https://www.example.com', options, config);
  const reportHtml = runnerResult.report;
  const fileName = `${new Date().toLocaleDateString().replace(/\//g, '-')}-${suffix}.html`;
  fs.writeFileSync(fileName, reportHtml);

  console.log('Report is done for', runnerResult.lhr.finalUrl);
  console.log('Performance score was', runnerResult.lhr.categories.performance.score * 100);

  await chrome.kill();
}

【问题讨论】:

    标签: node.js google-chrome lighthouse


    【解决方案1】:

    发现我需要先向 Heroku 添加一个特殊的 buildpack: heroku buildpacks:add --index 2 https://github.com/heroku/heroku-buildpack-google-chrome.git

    【讨论】:

      猜你喜欢
      • 2021-08-08
      • 2016-06-03
      • 2014-08-07
      • 2017-03-21
      • 1970-01-01
      • 2019-08-27
      • 1970-01-01
      • 2011-11-09
      相关资源
      最近更新 更多