GoogleChrome/lighthouse · error
UIStrings defined in file but not exported
Error message
UIStrings defined in file but not exported
What it means
Thrown during collection when the UISTRINGS_REGEX finds a UIStrings definition in the file text, but the module's runtime exports do not actually include UIStrings. The scanner found something that looks like a definition but it isn't exported, so messages cannot be correlated with runtime values for example/placeholder extraction.
Source
Thrown at core/scripts/i18n/collect-strings.js:586
for (const relativeToRootPath of files) {
const absolutePath = path.join(LH_ROOT, relativeToRootPath);
if (!process.env.CI) console.log('Collecting from', relativeToRootPath);
const content = fs.readFileSync(absolutePath, 'utf8');
const exportVars = await import(pathToFileURL(absolutePath).href);
const regexMatch = content.match(UISTRINGS_REGEX);
const exportedUIStrings = exportVars.UIStrings || exportVars.default?.UIStrings;
if (!regexMatch) {
// No UIStrings found in the file text or exports, so move to the next.
if (!exportedUIStrings) continue;
throw new Error('UIStrings exported but no definition found: ' + relativeToRootPath);
}
if (!exportedUIStrings) {
throw new Error('UIStrings defined in file but not exported');
}
// just parse the UIStrings substring to avoid ES version issues, save time, etc
const justUIStrings = 'const ' + regexMatch[0];
const parsedMessages = parseUIStrings(justUIStrings, exportedUIStrings);
for (const [key, parsed] of Object.entries(parsedMessages)) {
const {message, description, examples} = parsed;
const converted = convertMessageToCtc(message, examples);
// Don't include placeholders if there are none.
const placeholders = Object.keys(converted.placeholders).length === 0 ?
undefined :
converted.placeholders;
/** @type {CtcMessage} */
const ctc = {
message: converted.message,View on GitHub (pinned to 9515cd4e58)
Solutions
- Add `export` to the UIStrings definition: `export const UIStrings = {...}`.
- Ensure the exported name is exactly `UIStrings`.
- Confirm there is only one UIStrings definition and it is the one being exported.
Example fix
// before
const UIStrings = {
myMessage: 'My message',
};
// after
export const UIStrings = {
myMessage: 'My message',
}; Defensive patterns
Strategy: validation
Validate before calling
function isUIStringsExported(moduleExports) {
return Boolean(moduleExports.UIStrings || moduleExports.default?.UIStrings);
} Prevention
- Always use `export const UIStrings = {...}`.
- Verify the export keyword is present before running collect-strings.
- Check for duplicate/shadowed UIStrings definitions.
When it happens
Trigger: Defining `const UIStrings = {...}` in a file but forgetting the `export` keyword, or exporting it under a different name than `UIStrings`.
Common situations: Forgetting to add `export`; renaming the export but not the definition; defining UIStrings inside a function scope so it isn't a module-level export.
Related errors
- UIStrings exported but no definition found: ${relativeToRoot
- unsupported JSDoc comment: ${JSON.stringify(comment)}
- Incorrectly formatted @example: "${rawExample}"
- [${err.message}] Did not find the expected syntax in message
- Content cannot appear outside plural or select ICU messages.
AI-assisted analysis of GoogleChrome/lighthouse@9515cd4e58 (2026-08-13).
Data as JSON: /api/errors/da955a16c3463918.
Report an issue: GitHub.