{"record":{"id":"651b950a8edb6688","repo":"RocketChat/Rocket.Chat","slug":"moment-locale-not-found","errorCode":"moment-locale-not-found","errorMessage":"Moment locale not found: ${locale}","messagePattern":"Moment locale not found: (.+?)","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"warning","filePath":"apps/meteor/server/lib/getMomentLocale.ts","lineNumber":22,"sourceCode":"\tug: 'ug-cn',\n\tzh: 'zh-cn',\n};\n\nexport async function getMomentLocale(locale: string): Promise<string | undefined> {\n\tconst localeLower = locale.toLowerCase();\n\tconst localesPaths = [\n\t\t`moment-locales/${localeLower}.js`,\n\t\t`moment-locales/${String(localeLower.split('-').shift())}.js`,\n\t\t`moment-locales/${mapLocaleToMomentLocale[localeLower]}.js`,\n\t];\n\tfor await (const localePath of localesPaths) {\n\t\ttry {\n\t\t\treturn await Assets.getTextAsync(localePath);\n\t\t} catch (error) {\n\t\t\tcontinue;\n\t\t}\n\t}\n\tthrow new Meteor.Error('moment-locale-not-found', `Moment locale not found: ${locale}`);\n}\n","sourceCodeStart":4,"sourceCodeEnd":24,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/getMomentLocale.ts#L4-L24","documentation":"getMomentLocale tries three bundled asset paths for the requested locale — the exact lowercased code (e.g. pt-br), the language-only prefix (pt), and a mapped variant from mapLocaleToMomentLocale (ug→ug-cn, zh→zh-cn) — and throws this Meteor.Error when none of the moment-locales/*.js assets exist. The server then cannot serve the moment.js locale file for that language.","triggerScenarios":"A user's language resolves to a locale code with no matching bundled moment asset: unsupported/odd region variants, or custom language packs that added translations but no moment locale file and no mapLocaleToMomentLocale entry.","commonSituations":"Custom locale added without shipping the moment asset or updating the mapping; deployments where server assets are incomplete; clients requesting unusual Accept-Language variants.","solutions":["Use a supported language/locale code for the setting that feeds getMomentLocale","For custom locales, add the moment-locales/<locale>.js server asset and, when the moment name differs, an entry in mapLocaleToMomentLocale","As a caller, catch this error and fall back to the 'en' locale"],"exampleFix":"// before\nconst localeSrc = await getMomentLocale(locale);\n\n// after\nlet localeSrc: string | undefined;\ntry {\n  localeSrc = await getMomentLocale(locale);\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'moment-locale-not-found') {\n    localeSrc = await getMomentLocale('en');\n  } else {\n    throw err;\n  }\n}","handlingStrategy":"fallback","validationCode":"const SUPPORTED_MOMENT_LOCALES = ['en', 'de', 'pt-br', 'zh-cn' /* ... */];\nconst localeLower = locale.toLowerCase();\nconst safeLocale = SUPPORTED_MOMENT_LOCALES.includes(localeLower) ? locale : 'en';","typeGuard":null,"tryCatchPattern":"try {\n  return await getMomentLocale(locale);\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'moment-locale-not-found') {\n    return getMomentLocale('en'); // graceful degradation to default locale\n  }\n  throw err;\n}","preventionTips":["Stick to officially supported language codes","When adding custom languages, ship the matching moment-locales asset and update mapLocaleToMomentLocale","Never let locale loading break request handling — always fall back to 'en'"],"tags":["i18n","moment","locales","assets"],"backgroundTag":"locale-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}