You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用自定义配置时Lighthouse报错“No artifacts were defined”的解决方法

问题:Lighthouse运行报错"No artifacts were defined on the config"

问题复现

使用以下Node.js代码运行Lighthouse时触发报错:

import lighthouse from 'lighthouse';
import * as chromeLauncher from 'chrome-launcher';

const launchChromeAndRunLighthouse = async (url) => {
  const chrome = await chromeLauncher.launch();
  const options = { port: chrome.port };
  const runnerResult = await lighthouse(url, options, {
    settings: {
      extends: 'lighthouse:default',
      screenEmulation: {
        disabled: true,
      },
      extraHeaders: process.argv[2] === 'true' ? {
        'k8scluster': 'true',
      } : {},
      artifacts: {}, // 问题所在行
    }
  });
  await chrome.kill();
  return runnerResult.lhr;
};

const NUM_RUNS = process.argv[3] ? parseInt(process.argv[3]) : 10;
const targetURL = process.argv[4] || 'https://www.google.com/';

const runLighthouseMultipleTimes = async (url, numRuns) => {
  const runs = Array.from({ length: numRuns }, async () => {
    const result = await launchChromeAndRunLighthouse(url);
    return result;
  });

  return Promise.all(runs);
};

runLighthouseMultipleTimes(targetURL, NUM_RUNS)
  .then((results) => {
    const avgPerformanceScore =
      results.reduce((sum, result) => sum + result.categories.performance.score, 0) / NUM_RUNS;
    const avgAccessibilityScore =
      results.reduce((sum, result) => sum + result.categories.accessibility.score, 0) / NUM_RUNS;
    const avgBestPracticesScore =
      results.reduce((sum, result) => sum + result.categories['best-practices'].score, 0) / NUM_RUNS;
    const avgSEOscore = results.reduce((sum, result) => sum + result.categories.seo.score, 0) / NUM_RUNS;

    console.log(results);

    console.log(`Average Performance Score: ${avgPerformanceScore}`);
    console.log(`Average Accessibility Score: ${avgAccessibilityScore}`);
    console.log(`Average Best Practices Score: ${avgBestPracticesScore}`);
    console.log(`Average SEO Score: ${avgSEOscore}`);
  })
  .catch((err) => {
    console.error('Error running Lighthouse:', err);
  });

报错信息:

Error running Lighthouse: Error: No artifacts were defined on the config

该报错来自lighthouse/core/gather/navigation-runner.js中的检查逻辑:

async function _navigations(args) {
  const {
    driver,
    page,
    resolvedConfig,
    requestor,
    baseArtifacts,
    computedCache,
  } = args;

  if (!resolvedConfig.artifacts || !resolvedConfig.navigations) {
    throw new Error('No artifacts were defined on the config');
  }

  // 后续逻辑...
}

问题原因

你在自定义配置的settings中手动添加了artifacts: {},这会直接覆盖Lighthouse默认配置(lighthouse:default)中定义的完整artifacts集合。当导航运行器检查resolvedConfig.artifacts时,发现其为空对象,触发了报错逻辑。

解决方法

删除配置中的artifacts: {}行即可,默认配置已经包含了Lighthouse运行所需的所有artifacts定义。修改后的配置片段如下:

const runnerResult = await lighthouse(url, options, {
  settings: {
    extends: 'lighthouse:default',
    screenEmulation: {
      disabled: true,
    },
    extraHeaders: process.argv[2] === 'true' ? {
      'k8scluster': 'true',
    } : {},
    // 移除artifacts: {}这一行
  }
});

内容的提问来源于stack exchange,提问作者Aero Wang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 09:55:40