vite icon indicating copy to clipboard operation
vite copied to clipboard

'/nuxt-i18n/options.js' does not provide an export named 'localeMessages'

Open flozero opened this issue 4 years ago • 4 comments

Versions

nuxt-vite: 0.1.1 nuxt: 2.15.7

Reproduction

  • Install nuxt with nuxt-18n
  • Non-existent export 'localeMessages' is imported from resources/assets/js/.nuxt/nuxt-i18n/options.js

Description

Screen Shot 2021-06-18 at 7 00 11 PM

flozero avatar Jun 18 '21 23:06 flozero

I'm not sure why is that but just gonna add this extra screenshot:

Screenshot 2021-06-19 at 22 59 56

@pi0 any extra considerations that have to be taken into account when using addTemplate / addPlugin?

rchl avatar Jun 19 '21 21:06 rchl

I also get this issue with:

nuxt: 2.15.3
nuxt-vite: 0.1.1
nuxt-i18n: 6.27.1

romainmartinez avatar Jun 22 '21 15:06 romainmartinez

Use langDir + translation files seems to eliminate the error.

  // nuxt.config.js
  i18n: {
    locales: 
      [{
        code: 'zh',
        file: 'zh-HK.js'
      }, {
        code: 'en',
        file: 'en-GB.js'
      }],
    defaultLocale: 'zh',
    langDir: 'lang/', // <---
    vueI18n: {
      fallbackLocale: 'zh',
    }
  },
// lang/en-GB.js
export default {
  welcome: 'Welcome'
}
// package.json
"nuxt": "^2.15.7",
"nuxt-vite": "^0.1.0",
"nuxt-i18n": "^6.27.2",

It looks like the plugin checks for langDir before exporting localeMessages in options.js

// node_modules/nuxt-i18n/src/templates/options.js
if (langDir) { %>
export const localeMessages = {
...

See documentation for landDir option and translation files https://i18n.nuxtjs.org/options-reference#langdir https://i18n.nuxtjs.org/lazy-load-translations/

jolc avatar Aug 01 '21 15:08 jolc

Thanks for that. So it's actually an issue with nuxt-i18n. Fixing in https://github.com/nuxt-community/i18n-module/pull/1251.

rchl avatar Aug 02 '21 07:08 rchl