GoogleChrome/lighthouse · error
missing metric ${metricName}
Error message
missing metric ${metricName} What it means
Thrown during baseline comparison when a metric present in the computed (HEAD) Lantern results is not found in the expected baseline results for a given site. The comparison iterates actualLantern's keys and requires every one to exist in expectedLantern.
Source
Thrown at core/scripts/lantern/assert-baseline-lantern-values-unchanged.js:40
if (!fs.existsSync(HEAD_PATH) || !fs.existsSync(BASELINE_PATH)) {
throw new Error('Usage $0 <computed file>');
}
const computedResults = readJson(HEAD_PATH);
const expectedResults = readJson(BASELINE_PATH);
/** @type {Array<{url: string, maxDiff: number, diffsForSite: Array<DiffForSite>}>} */
const diffs = [];
for (const entry of computedResults.sites) {
// @ts-expect-error - over-aggressive implicit any on candidate
const expectedLantern = expectedResults.sites.find(candidate => entry.url === candidate.url);
const actualLantern = entry.lantern;
let maxDiff = 0;
/** @type {DiffForSite[]} */
const diffsForSite = [];
Object.keys(actualLantern).forEach(metricName => {
if (!(metricName in expectedLantern)) throw new Error(`missing metric ${metricName}`);
const actual = Math.round(actualLantern[metricName]);
const expected = Math.round(expectedLantern[metricName]);
const diff = actual - expected;
if (Math.abs(diff) > 0) {
maxDiff = Math.max(maxDiff, Math.abs(diff));
diffsForSite.push({metricName, actual, expected, diff});
}
});
if (maxDiff > 0) diffs.push({url: entry.url, maxDiff, diffsForSite});
}
if (diffs.length) {
console.log(`❌ FAIL ${diffs.length} change(s) between expected and computed!\n`);
diffs.sort((a, b) => b.maxDiff - a.maxDiff).forEach(site => {
console.log(chalk.magenta(site.url));View on GitHub (pinned to 9515cd4e58)
Solutions
- Regenerate the baseline file (`npm run lantern:update-baseline` or equivalent) so it includes all current metrics.
- If the metric is intentionally new and the baseline is correct, update the baseline to include the new metric.
- Verify both HEAD and baseline were generated from the same set of sites/metrics.
Defensive patterns
Strategy: validation
Validate before calling
function assertMetricsExist(actualLantern, expectedLantern) {
for (const metricName of Object.keys(actualLantern)) {
if (!(metricName in expectedLantern)) {
throw new Error(`missing metric ${metricName}`);
}
}
} Prevention
- Regenerate the baseline whenever a new metric is added to Lantern output.
- Keep HEAD and baseline generation on the same metric set.
- Run baseline update as part of the PR that adds a new metric.
When it happens
Trigger: A new metric was added to the Lantern output but the baseline file hasn't been regenerated to include it; the baseline was generated from an older version.
Common situations: Adding a new metric to the Lantern collector without updating the baseline; using a stale baseline from a different branch.
Related errors
- Usage $0 <computed file>
- FCP All Frames not implemented in lantern
- LCP All Frames not implemented in lantern
- run failed to get metrics
- No lantern metrics available, did you run run-on-all-assets.
AI-assisted analysis of GoogleChrome/lighthouse@9515cd4e58 (2026-08-13).
Data as JSON: /api/errors/e5821c3415e6b42a.
Report an issue: GitHub.