nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.71k stars 476 forks source link

Not able to add i18n config in nuxt.config.ts #3011

Closed mir1198yusuf closed 2 months ago

mir1198yusuf commented 3 months ago

Environment


Reproduction

This error does not come on StackBlitz or CodeSandbox

Describe the bug

When I add i18n config to defineNuxtConfig, I get this error while adding below i18n object

nuxt.config.ts

defineNuxtConfig({
...
modules: [..."@nuxtjs/i18n"],
i18n: {
     vueI18n: {
            strategy: 'prefix_except_default',
            defaultLocale: 'en-IN',
            locales: [
                {
                    code: 'us',
                    name: 'English',
                    iso: 'en-US',
                },
                {
                    code: 'en-IN',
                    name: 'English',
                    iso: 'en-IN',
                },
            ],
        }
}
...
})

Error on hovering vueI18n:

Object literal may only specify known properties, and 'vueI18n' does not exist in type 'Partial<ModuleOptions>'.ts(2353)
module.d.ts(470, 9): The expected type comes from property 'i18n' which is declared here on type 'InputConfig<NuxtConfig, ConfigLayerMeta>'

Additional context

No response

Logs

No response

steffenstolze commented 3 months ago

This is a path to a file.

image

add a i18n.config.ts file next to your nuxt config with your content:

export default {
    ... your config
};

and adjust your nuxt config like this if you want to use a custom name for the config file:

i18n: {
     vueI18n: './my-crazy-i18n-config.ts'
....
}
BobbieGoede commented 2 months ago

@steffenstolze is right, configuring vue-i18n specific options was changed in v8, please refer to https://i18n.nuxtjs.org/docs/guide/migrating#deprecated-vuei18n-option-to-not-accept-createi18n-options for more details.