angular/angular-cli · error · Error
Flat output is only supported when inlining one locale.
Error message
Flat output is only supported when inlining one locale.
What it means
The Angular CLI's i18n inlining step throws this when 'flat output' (writing translated bundles without per-locale subdirectories) is requested but more than one locale is being inlined. Flat output can only unambiguously hold a single locale's translations, so the library rejects the combination up front in inlineLocales.
Source
Thrown at packages/angular_devkit/build_angular/src/utils/process-bundle.ts:114
return { diagnostics, plugins };
}
interface LocalizePosition {
start: number;
end: number;
messageParts: TemplateStringsArray;
expressions: types.Expression[];
}
const localizeName = '$localize';
export async function inlineLocales(options: InlineOptions) {
if (!i18n || i18n.inlineLocales.size === 0) {
return { file: options.filename, diagnostics: [], count: 0 };
}
if (i18n.flatOutput && i18n.inlineLocales.size > 1) {
throw new Error('Flat output is only supported when inlining one locale.');
}
const hasLocalizeName = options.code.includes(localizeName);
if (!hasLocalizeName && !options.setLocale) {
return inlineCopyOnly(options);
}
await loadLocalizeTools();
let ast: ParseResult | undefined | null;
try {
ast = parseSync(options.code, {
babelrc: false,
configFile: false,
sourceType: 'unambiguous',
filename: options.filename,
});
} catch (error) {View on GitHub (pinned to bb72145f9a)
Solutions
- Reduce the set of locales being inlined to exactly one (e.g. run the build once per locale with `--localize=fr`).
- Disable flat output so each locale is written to its own subdirectory under outputPath.
- Check angular.json: ensure `projects.<p>.architect.build.options.localize` and i18n output options are consistent — multiple locales require non-flat output.
Example fix
// angular.json - before
"options": { "localize": ["en", "fr"], "outputPath": "dist/app" }
// after
"options": { "localize": true, "outputPath": "dist/app" } // per-locale subdirs: dist/app/en, dist/app/fr Defensive patterns
Strategy: validation
Validate before calling
if (i18nOptions.flatOutput && i18nOptions.inlineLocales.size > 1) {
throw new Error('Flat output requires exactly one locale; use per-locale subdirectories instead.');
} Type guard
function supportsFlatOutput(i18n: { flatOutput: boolean; inlineLocales: Set<string> }): boolean {
return !(i18n.flatOutput && i18n.inlineLocales.size > 1);
} Try / catch
try {
await inlineLocales(options);
} catch (e) {
if (e.message.includes('Flat output is only supported')) {
// fall back to non-flat output or single-locale runs
} else throw e;
} Prevention
- Only enable flat output when building a single locale.
- Prefer the default per-locale subdirectory output when localizing multiple locales.
- Validate angular.json `localize` and i18n output options in CI before building.
- Run `ng build --localize=fr` per locale instead of batching locales with flat output.
When it happens
Trigger: Calling inlineLocales with i18n.flatOutput enabled while i18n.inlineLocales contains 2 or more locales — e.g. an Angular project configured with `"localize": ["en", "fr"]` plus `outputPath`/i18n settings that yield flat output.
Common situations: angular.json mistakes: setting `localize` to an array of locales while configuring the build for flat output (e.g. via `i18n` browser-builder options or missing `subPath` configuration); upgrading projects that previously inlined one locale and then adding a second locale without switching to per-locale subdirectory output.
Related errors
- ${msg}\nAn error occurred inlining file "${options.filename}
- Unknown error occurred inlining file "${options.filename}"
- Unknown error occurred processing bundle for "${options.file
- Unsupported package manager: "${name}"
- The configured package manager, '${this.descriptor.binary}',
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/92261f6620f06bcb.
Report an issue: GitHub.