cube-js/cube · warning
Failed to detect locale
Error message
Failed to detect locale
What it means
Cube client detects the runtime's default locale using Intl.NumberFormat().resolvedOptions().locale. If constructing Intl.NumberFormat throws (rare; environments without ICU), detectLocale warns and defaults to 'en-US'.
Source
Thrown at packages/cubejs-client-core/src/format.ts:79
abbr_4: '.4~s',
abbr_5: '.5~s',
abbr_6: '.6~s',
accounting: '(,.2~f',
accounting_0: '(,.0f',
accounting_1: '(,.1~f',
accounting_2: '(,.2~f',
accounting_3: '(,.3~f',
accounting_4: '(,.4~f',
accounting_5: '(,.5~f',
accounting_6: '(,.6~f',
};
function detectLocale() {
try {
return new Intl.NumberFormat().resolvedOptions().locale;
} catch (e) {
console.warn('Failed to detect locale', e);
return 'en-US';
}
}
const currentLocale = detectLocale();
const DEFAULT_DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S';
const DEFAULT_DATE_FORMAT = '%Y-%m-%d';
const DEFAULT_DATE_WEEK_FORMAT = '%Y-%m-%d W%V';
const DEFAULT_DATE_MONTH_FORMAT = '%Y %b';
const DEFAULT_DATE_QUARTER_FORMAT = '%Y-Q%q';
const DEFAULT_DATE_YEAR_FORMAT = '%Y';
function getFormatByGrain(grain?: string): string {
// Grains that should show date and time (sub-day granularities)
const dateTimeGrains = ['second', 'minute', 'hour'];
View on GitHub (pinned to 7d981676b3)
Solutions
- Run on a runtime with ICU support (standard Node builds include it; use node with full-icu otherwise)
- Accept the fallback — formatting proceeds with en-US
- Polyfill Intl if targeting minimal environments
Defensive patterns
Strategy: fallback
Validate before calling
const hasIntl = typeof Intl !== 'undefined' && typeof Intl.NumberFormat === 'function';
Type guard
function hasIntlNumberFormat(): boolean {
return typeof Intl !== 'undefined' && typeof Intl.NumberFormat === 'function';
} Try / catch
try {
locale = new Intl.NumberFormat().resolvedOptions().locale;
} catch {
locale = 'en-US';
} Prevention
- Deploy on runtimes with ICU support
- Polyfill Intl for minimal environments
- Treat en-US fallback as expected behavior in locale-less runtimes
When it happens
Trigger: Module load time: currentLocale = detectLocale() runs when the format module is imported and Intl.NumberFormat() throws in the current runtime.
Common situations: Node built without ICU; embedded/minimal JS runtimes; stripped-down browser environments lacking Intl.
Related errors
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/95e64941e8f0e37d.
Report an issue: GitHub.