Why i use installModule nuxtjs/i18n in nuxt module cannot working when use 2 more modules

https://github.com/nuxt-modules/i18n/issues/3193 --- Environment Details - Operating System: Darwin
- Node Version: v22.0.0
- Nuxt Version: 3.13.2
- CLI Version: 3.15.0
- Nitro Version: 2.9.7
- Package Manager: [email protected]
- Modules & Configurations: - Runtime Modules:
@nuxtjs/[email protected] - Build Modules: None specified. --- Steps to Reproduce Access the reproduction environment on Stackblitz: Stackblitz Project Bug Description While configuring nuxtjs/i18n in module.ts as per the official documentation, I used the following setup:
await installModule('@nuxtjs/i18n', {
langDir: resolve('./lang'),
locales: [
{ code: 'en', file: resolve('./lang/en.json') },
{ code: 'fr', file: resolve('./lang/fr.json') },
]
});
await installModule('@nuxtjs/i18n', {
langDir: resolve('./lang'),
locales: [
{ code: 'en', file: resolve('./lang/en.json') },
{ code: 'fr', file: resolve('./lang/fr.json') },
]
});
In nuxt.config.ts, when specifying the modules like this:
modules: [
'module-1', // working
'@nuxtjs/i18n'
]
modules: [
'module-1', // working
'@nuxtjs/i18n'
]
it works as expected. However, when arranging the modules in other combinations, the functionality breaks as shown below: - Configuration 1:
modules: [
'module-1', // working
'module-2', // not working
'@nuxtjs/i18n'
]

modules: [
'module-1', // working
'module-2', // not working
'@nuxtjs/i18n'
]

- Configuration 2:
modules: [
'module-2', // working
'module-1', // not working
'@nuxtjs/i18n'
]

modules: [
'module-2', // working
'module-1', // not working
'@nuxtjs/i18n'
]

Additional Context I am looking for guidance on achieving the intended configuration or an alternative solution.
GitHub
Issue with installModule for nuxtjs/i18n Failing When Used with Mu...
Environment Details Operating System: Darwin Node Version: v22.0.0 Nuxt Version: 3.13.2 CLI Version: 3.15.0 Nitro Version: 2.9.7 Package Manager: [email protected] Modules & Configurations: Runtime M...
Hung Nguyen
StackBlitz
Nuxt - Starter - StackBlitz
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
2 Replies
kapa.ai
kapa.ai2mo ago
Hi @hungnguyen1501. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the knowledge sources, I can offer some insights into your issue with the @nuxtjs/i18n module and multiple modules in Nuxt. The problem you're experiencing seems to be related to module ordering and potential conflicts between modules. This is a known issue that has been discussed in the Nuxt community. 1. Module Ordering: As mentioned in the Github issue (https://github.com/nuxt/nuxt/issues/29183), the order of modules can sometimes cause unexpected behavior. In your case, changing the order of module-1 and module-2 affects their functionality. 2. Module Independence: According to a comment by a Nuxt team member in the same Github issue, "Modules should not be dependent on ordering and if they are it's a bug in the module that should be reported and resolved." This suggests that the issue might be with one of your custom modules rather than @nuxtjs/i18n itself. 3. Configuration Approach: Several users have reported success by separating the i18n configuration. As suggested in a Stack Overflow answer (https://stackoverflow.com/questions/78240834), you might try moving your i18n configuration to a separate file and referencing it in your nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
vueI18n: './i18n.config.ts'
}
})

export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
vueI18n: './i18n.config.ts'
}
})

4. Nuxt 3 Compatibility: Ensure that you're using the latest version of @nuxtjs/i18n that's compatible with Nuxt 3. The module has undergone significant changes to support Nuxt 3. 5. Build Context vs Runtime Context: As explained in the Nuxt documentation (https://nuxt.com/docs/guide/going-further/internals#runtime-context-vs-build-context), there's a distinction between build-time and runtime contexts in Nuxt. Make sure your modules are correctly set up for the build context. 6. Reporting Bugs: If you've confirmed that this is indeed a bug, consider reporting it as suggested in the Nuxt documentation on reporting bugs (https://nuxt.com/docs/community/getting-help#could-there-be-a-bug). Given the complexity of your setup and the lack of specific information about module-1 and module-2, it's difficult to pinpoint the exact cause of the issue. You might want to: 1. Check for any conflicts between your custom modules and @nuxtjs/i18n. 2. Try isolating each module to see which one is causing the issue. 3. Ensure that your custom modules are correctly implemented for Nuxt 3. 4. Consider reporting this as a potential bug to the Nuxt team with a minimal reproduction. If the issue persists after trying these suggestions, you may need to provide more details about your custom modules for further assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@541869675752062988> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Want results from more Discord servers?
Add your server