nuxt / vite

⚡ Vite Experience with Nuxt 2
https://vite.nuxtjs.org
1.39k stars 46 forks source link

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

Open flozero opened 3 years ago

flozero commented 3 years ago

Versions

nuxt-vite: 0.1.1 nuxt: 2.15.7

Reproduction

Description

Screen Shot 2021-06-18 at 7 00 11 PM
rchl commented 3 years ago

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?

romainmartinez commented 3 years ago

I also get this issue with:

nuxt: 2.15.3
nuxt-vite: 0.1.1
nuxt-i18n: 6.27.1
jolc commented 3 years ago

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/

rchl commented 3 years ago

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