首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >灯塔/ Chrome启动器错误:环境变量CHROME_PATH必须设置为Chromium版本54.0或更高版本的内部版本的可执行文件

灯塔/ Chrome启动器错误:环境变量CHROME_PATH必须设置为Chromium版本54.0或更高版本的内部版本的可执行文件
EN

Stack Overflow用户
提问于 2021-02-10 07:14:45
回答 1查看 991关注 0票数 1

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

代码语言:javascript
复制
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]: }

下面是我的脚本:

代码语言:javascript
复制
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();
}
EN

回答 1

Stack Overflow用户

发布于 2021-02-11 01:48:29

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66128648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档