i18n
i18n copied to clipboard
Cannot read properties of undefined (reading 'messages')
Environment
- Operating System: Darwin
- Node Version: v20.10.0
- Nuxt Version: 3.12.2
- CLI Version: 3.12.0
- Nitro Version: 2.9.6
- Package Manager: [email protected]
- Builder: -
- User Config: devtools, experimental, ssr, typescript, srcDir, runtimeConfig, extends, modules, sourcemap, ui, postcss, tailwindcss, vite, nitro, components, css, imports, i18n
- Runtime Modules: @nuxt/test-utils/[email protected], @pinia/[email protected], @nuxt/[email protected], @nuxtjs/[email protected], @nuxt/[email protected], @vueuse/[email protected], @nuxt/[email protected], [email protected], @nuxt/[email protected], @nuxtjs/[email protected]
- Build Modules: -
Reproduction
Passing an H3 event from an API eventHandler to a function in the server/utils directory causes this error:
Cannot read properties of undefined (reading 'messages')
Describe the bug
My function where the error originates:
Looking at the stack trace at the bottom I think I've manage to figure out why it's erroring with this.
Firstly the localeDector is called here with 1 param (event)
This seems to be calling this localeDetector function which requires the i18nContext
context as it's second param.
Which is why this line fails:
await loadAndSetLocaleMessages(locale, localeLoaders, i18nContext.messages);
because i18nContext is undefined.
ERROR Cannot read properties of undefined (reading 'messages')
at localeDetector (.nuxt/dev/index.mjs:3233:73)
at useTranslation (node_modules/@intlify/h3/dist/index.mjs:38:39)
at generateAndSaveTokens (.nuxt/dev/index.mjs:2717:19)
at Object.handler (.nuxt/dev/index.mjs:6889:47)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async node_modules/h3/dist/index.mjs:1962:19
at async Object.callAsync (node_modules/unctx/dist/index.mjs:72:16)
at async Object.callAsync (node_modules/unctx/dist/index.mjs:72:16)
at async Server.toNodeHandle (node_modules/h3/dist/index.mjs:2249:7)
Additional context
No response
Logs
No response