i18n icon indicating copy to clipboard operation
i18n copied to clipboard

Cannot read properties of undefined (reading 'messages')

Open alexcroox opened this issue 7 months ago • 2 comments

Environment

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:

image

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)

image

This seems to be calling this localeDetector function which requires the i18nContext context as it's second param.

image

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

alexcroox avatar Jul 02 '24 19:07 alexcroox