{"record":{"id":"d1fe9544d28e8eb6","repo":"marmelab/react-admin","slug":"the-i18nprovider-returned-a-promise-for-the-messag","errorCode":null,"errorMessage":"The i18nProvider returned a Promise for the messages of the default locale (${initialLocale}). Please update your i18nProvider to return the messages of the default locale in a synchronous way.","messagePattern":"The i18nProvider returned a Promise for the messages of the default locale \\((.+?)\\)\\. Please update your i18nProvider to return the messages of the default locale in a synchronous way\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ra-i18n-polyglot/src/index.ts","lineNumber":38,"sourceCode":" *     fr: frenchMessages,\n *     en: englishMessages,\n * };\n * const i18nProvider = polyglotI18nProvider(\n *     locale => messages[locale],\n *     'en',\n *     [{ locale: 'en', name: 'English' }, { locale: 'fr', name: 'Français' }]\n * )\n */\nexport default (\n    getMessages: GetMessages,\n    initialLocale: string = 'en',\n    availableLocales: Locale[] | any = [{ locale: 'en', name: 'English' }],\n    polyglotOptions: any = {}\n): I18nProvider => {\n    let locale = initialLocale;\n    const messages = getMessages(initialLocale);\n    if (messages instanceof Promise) {\n        throw new Error(\n            `The i18nProvider returned a Promise for the messages of the default locale (${initialLocale}). Please update your i18nProvider to return the messages of the default locale in a synchronous way.`\n        );\n    }\n\n    let availableLocalesFinal, polyglotOptionsFinal;\n    if (Array.isArray(availableLocales)) {\n        // third argument is an array of locales\n        availableLocalesFinal = availableLocales;\n        polyglotOptionsFinal = polyglotOptions;\n    } else {\n        // third argument is the polyglotOptions\n        availableLocalesFinal = [{ locale: 'en', name: 'English' }];\n        polyglotOptionsFinal = availableLocales;\n    }\n    const polyglot = new Polyglot({\n        locale,\n        phrases: { '': '', ...messages },\n        ...polyglotOptionsFinal,","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-i18n-polyglot/src/index.ts#L20-L56","documentation":"ra-i18n-polyglot's polyglotI18nProvider requires getMessages for the initial (default) locale to return messages synchronously, because it must build the Polyglot instance eagerly at setup time. If the function returns a Promise for the default locale, the provider cannot proceed and throws at creation time.","triggerScenarios":"polyglotI18nProvider(locale => fetch(...)...) with the default locale resolved via an async call; passing an async getMessages function whose first invocation (for initialLocale) is asynchronous; using jsonServerProvider-style async message loading for the startup locale.","commonSituations":"Migrating from a fully async i18n setup; loading translations from an API for all locales including the initial one; mixing static imports for 'en' with dynamic imports for other locales but forgetting to keep the default synchronous.","solutions":["Make getMessages return messages synchronously for the default locale (static import or preloaded object)","Load async locales only for non-default locales, using async/await inside getMessages with a cached synchronous default","Pre-fetch all messages before creating the provider, then use a synchronous getMessages that reads from the cache"],"exampleFix":"// before\npolyglotI18nProvider(async locale => {\n    const messages = await fetch(`/i18n/${locale}.json`).then(r => r.json());\n    return messages;\n}, 'en');\n// after\nimport en from './i18n/en.json';\nconst cache = { en };\npolyglotI18nProvider(locale => {\n    if (cache[locale]) return cache[locale];\n    return fetch(`/i18n/${locale}.json`)\n        .then(r => r.json())\n        .then(messages => { cache[locale] = messages; return messages; });\n}, 'en');","handlingStrategy":"validation","validationCode":"const getMessages = locale => {\n    const messages = cache[locale];\n    if (messages instanceof Promise) {\n        throw new Error(`getMessages returned a Promise for default locale: ${locale}`);\n    }\n    return messages;\n};","typeGuard":"const isSyncMessages = (m: unknown): m is Record<string, any> =>\n    !(m instanceof Promise) && typeof m === 'object' && m !== null;","tryCatchPattern":"try {\n    const i18nProvider = polyglotI18nProvider(getMessages, 'en', availableLocales);\n} catch (e) {\n    if (e instanceof Error && e.message.includes('returned a Promise for the messages')) {\n        console.error('Default locale messages must be synchronous; preload translations first');\n        throw e;\n    }\n    throw e;\n}","preventionTips":["Always statically import the default locale messages","Cache async locale loads and return the default synchronously from a cache","Never use an async function directly as getMessages for the default locale","Add a smoke test that constructs the provider at startup"],"tags":["i18n","async","configuration"],"backgroundTag":"async-messages-for-default-locale","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}