有人知道是什么原因导致这个错误吗?这是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();
}发布于 2021-02-11 01:48:29
我发现我首先需要向Heroku添加一个特殊的构建包:heroku buildpacks:add --index 2 https://github.com/heroku/heroku-buildpack-google-chrome.git
https://stackoverflow.com/questions/66128648
复制相似问题