Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with installModule for nuxtjs/i18n Failing When Used with Multiple Nuxt Modules #3193

Closed
hungnguyen18 opened this issue Oct 31, 2024 · 7 comments

Comments

@hungnguyen18
Copy link

hungnguyen18 commented Oct 31, 2024


Environment Details


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') },
  ]
});

In nuxt.config.ts, when specifying the modules like this:

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'
    ]
  • Configuration 2:

    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.

Logs

No logs generated in this scenario.


@hungnguyen18 hungnguyen18 changed the title Why i use installModule nuxtjs/i18n in nuxt module cannot working when use 2 more modules Issue with installModule for nuxtjs/i18n Failing When Used with Multiple Nuxt Modules Oct 31, 2024
@BobbieGoede
Copy link
Collaborator

This is main issues I have with installModule, a module really only runs its setup once regardless of how many other modules try to install it using installModule. The same happens for layers installing the same module, but layer options are stored and can be retrieved/merged by the module that's being installed.

@danielroe is there any way to make installModule work when it's called in multiple places? The options are not stored someplace like they are for layers nuxt.options._layers right?

@userquin
Copy link
Collaborator

userquin commented Nov 1, 2024

installModule is about installing a module, we cannot use it to "merge" i18n options since the module will be installed only once and next calls will be discarded when Nuxt (Nuxt Kit) installing it and already found.

You can also use layer + module registering i18n module options: i18n will merge them for you.

@hungnguyen18
Copy link
Author

installModule is about installing a module, we cannot use it to "merge" i18n options since the module will be installed only once and next calls will be discarded when Nuxt (Nuxt Kit) installing it and already found.

You can also use layer + module registering i18n module options: i18n will merge them for you.

I've previously tried your approach and was able to resolve the issue to some extent. However, without installing the @nuxtjs/i18n module, I'm still unable to resolve useI18n in #imports within src/runtime, which remains inconvenient 😅. This limitation also affects testing with Vitest, where useI18n isn’t recognized.

I'm wondering if the @nuxtjs/i18n team might have a solution to address this issue in a way that also supports multi-module compatibility.

Image

@BobbieGoede
Copy link
Collaborator

What would probably work best for your use case is to use installModule without passing options just to ensure the module is being installed and use the i18n:registerModule to register the locales.

@userquin
Copy link
Collaborator

userquin commented Nov 1, 2024

can you check if present in .nuxt/imports.d.ts?

Image

@hungnguyen18
Copy link
Author

What would probably work best for your use case is to use installModule without passing options just to ensure the module is being installed and use the i18n:registerModule to register the locales.

Thanks I followed your config and it worked and achieved the desired goal 🥰, so I will close this issue
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants