#node.js #google-chrome #lighthouse
#node.js #google-chrome #lighthouse
Вопрос:
Кто-нибудь знает, что может быть причиной этой ошибки? Это ошибка, которая отображается в журналах 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();
}
Ответ №1:
Обнаружил, что мне нужно сначала добавить специальный пакет сборки в Heroku: heroku buildpacks:add --index 2 https://github.com/heroku/heroku-buildpack-google-chrome.git