With nuxt-i18n upgrade from v6.3 to v6.13.12, other plugins are no longer available
See original GitHub issueVersion
nuxt-i18n: 6.13.12 nuxt: 2.14.3
Nuxt configuration
- universal
Nuxt-i18n configuration
i18n: {
locales,
// defaultLocale: 'fra-fr',
lazy: true,
langDir: 'services/lang/',
seo: false,
// Prefix all url, including the default one
strategy: 'prefix',
// Disable redirection base on browser, we will implement our own strategy
detectBrowserLanguage: 'false',
// Localized routes
parsePages: false,
pages: {
'magazine/articles/_article': {
'deu-de': '/magazine/artikel/:article',
'esp-es': '/magazine/articulos/:article',
'ita-it': '/magazine/articoli/:article',
'por-br': '/magazine/artigulos/:article',
},
'products/_id': {
'esp-es': '/productos/:id',
'fra-fr': '/produits/:id',
'fra-ca': '/produits/:id',
'por-br': '/produtos/:id',
'deu-de': '/produkte/:id',
'ita-it': '/prodotti/:id',
},
cart: {
'fra-fr': '/selection',
'fra-ca': '/selection',
'deu-de': '/kaufen',
'esp-es': '/cesta',
'ita-it': '/acquistare',
'por-br': '/carrinho',
},
checkout: {
'fra-fr': '/finaliser-ma-commande',
'fra-ca': '/finaliser-ma-commande',
'deu-de': '/zur-kasse',
'esp-es': '/continuar',
'por-br': '/finalizar-a-compra',
},
},
// TO BE CHANGED LATER FOR LOCAL CHOICE PAGE
// rootRedirect: 'fra-fr',
// http://kazupon.github.io/vue-i18n/api/#silenttranslationwarn
// http://kazupon.github.io/vue-i18n/api/#silentfallbackwarn
...(process.env.LVF_I18N_SILENT_WARN || process.env.NODE_ENV === 'production'
? {
vueI18n: { silentTranslationWarn: true, silentFallbackWarn: true },
}
: {}),
}
Steps to reproduce
- configure the lazy loading of the lang files
- implement axios to get a lang file
- write and load a custom plugin with nuxt module (ex: $logger with consola), use it to log in lang requester service
- load nuxt-i18n module after the logger “plugin” module
- run your nuxt application, open an url, nuxt-i18n will try to request a lang file
- $logger plugin is not found in context
// nuxt.config.js
{
modules: ['~/modules/logger', ['nuxt-i18n', {...}]]
}
// src/modules/logger.js
export default function module() {
this.addPlugin(path.resolve(__dirname, '../plugins/nuxt/logger.js'));
}
// src/services/lang/ara-ae.js
const cli = axios.create()
export default ctx => {
ctx.app.$logger.info('Request for ara-ae')
return cli.get('https://www.mydomain.com/ara-ae.json', {...})
}
What is Expected?
As expected with nuxt-i18n 6.3, plugin (ctx.app.$logger) is available during lazy load on server side.
What is actually happening?
Plugin is not available during lazy load on server side.
ERROR Cannot read property 'info' of undefined
Regards
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top Results From Across the Web
With nuxt-i18n upgrade from v6.3 to v6.13.12, other plugins ...
With nuxt-i18n upgrade from v6.3 to v6.13.12, other plugins are no longer ... Plugin is not available during lazy load on server side....
Read more >I18n Module - Nuxt
Custom routes optimized for Nuxt 3 file based routing - by @kazupon ... Upgrade vue-i18n-routing for peer deps issue - by @kazupon in...
Read more >https://raw.githubusercontent.com/nuxt-community/n...
[6.28.1](https://github.com/nuxt-community/i18n-module/compare/v6.28.0...v6.28.1) ... don't skip the cookie if no locale is detected in the route ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There is no way to make the order work for all cases.
If there are only modules at play then the plugin registration order is opposite of the module registration order (since adding plugin from a module adds it at the start of the list).
If there are also “loose” plugins mixed into the picture then I’m not sure what is currently the order but judging from your comment, the “loose” plugins are registered before modules so run first.
In your case, you should probably create a simple module that adds the plugin using
this.addPlugin
. Then you can control the order by changing the order modules are registered.This fix was to make the order predictable within modules registration.
Fix released in v6.15.1