GoogleChrome/lighthouse · error

expected locale file to exist: ${traceEnginePath}

Error message

expected locale file to exist: ${traceEnginePath}

What it means

Thrown during locale merging when a locale JSON file is expected to exist in the trace_engine strings directory but is missing on disk. The script iterates locale files and for each expects a corresponding trace_engine locale file; a missing one breaks the merge of trace_engine translations into Lighthouse's locale set.

Source

Thrown at core/scripts/i18n/collect-strings.js:814

  const traceEngineStringsDir = `${LH_ROOT}/node_modules/@paulirish/trace_engine/locales`;
  const lhStringsDir = `${LH_ROOT}/shared/localization/locales`;
  for (const file of glob.sync(`${lhStringsDir}/*.json`)) {
    let name = path.basename(file);
    if (name.endsWith('.ctc.json')) {
      continue;
    }

    if (name === 'ar-XB.json') {
      name = 'ar.json';
    }

    if (['en-XA.json'].includes(name)) {
      continue;
    }

    const traceEnginePath = `${traceEngineStringsDir}/${name}`;
    if (!fs.existsSync(traceEnginePath)) {
      throw new Error(`expected locale file to exist: ${traceEnginePath}`);
    }

    const traceEngineStrings = JSON.parse(fs.readFileSync(traceEnginePath, 'utf-8'));
    const strings = JSON.parse(fs.readFileSync(file, 'utf-8'));
    for (const [key, value] of Object.entries(traceEngineStrings)) {
      const lhKey = `node_modules/@paulirish/trace_engine/${key.replace('.ts', '.js')}`;

      // TODO: why is this so malformed? see b/399706272
      if (['he.json', 'ru.json', 'ta.json'].includes(name) && lhKey === 'node_modules/@paulirish/trace_engine/generated/Deprecation.js | ObsoleteCreateImageBitmapImageOrientationNone') {
        continue;
      }

      value.message = value.message
        .replace(/\\\\/g, '')
        .replace(`{imageOrientation: 'from-image'}`, `\\\\{imageOrientation: 'from-image'\\\\}`)
        .replace(`{imageOrientation: ''from-image''}`, `\\\\{imageOrientation: ''from-image''\\\\}`)
        .replace(`{imageOrientation: "from-image"}`, `\\\\{imageOrientation: "from-image"\\\\}`)
        .replace(`{imageOrientation: 'from-image'\\}`, `\\\\{imageOrientation: 'from-image'\\\\}`)

View on GitHub (pinned to 9515cd4e58)

Solutions

  1. Run `npm install` and the relevant build steps to regenerate trace_engine locale files.
  2. Check if the trace_engine package version in node_modules matches package.json expectations.
  3. If the locale genuinely doesn't exist in trace_engine yet, add a skip/continue for that locale or wait for the upstream package update.
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const path = require('path');
function traceEngineLocaleExists(traceEngineStringsDir, name) {
  return fs.existsSync(path.join(traceEngineStringsDir, name));
}

Try / catch

for (const file of localeFiles) {
  const traceEnginePath = `${traceEngineStringsDir}/${name}`;
  if (!fs.existsSync(traceEnginePath)) {
    console.warn(`Skipping missing trace engine locale: ${traceEnginePath}`);
    continue;
  }
  // ... proceed with merge
}

Prevention

When it happens

Trigger: Running collect-strings (which produces and merges locale files) when the @paulirish/trace_engine dependency hasn't been fully installed, or when a locale exists in Lighthouse but not yet in trace_engine's generated output.

Common situations: Fresh checkout without `npm install` / `npm run build-all`; trace_engine version bump that removed or renamed a locale; adding a new locale to Lighthouse before trace_engine ships it.

Related errors


AI-assisted analysis of GoogleChrome/lighthouse@9515cd4e58 (2026-08-13). Data as JSON: /api/errors/5bb4ea31305c4f35. Report an issue: GitHub.