How to import useI18n and useLocalePath composables in Nuxt3
See original GitHub issueHi. Firstly, i want to thank you for your great work on this package.
I’m using nuxt3 rc4 (with rc3 the errors were the same) and @nuxtjs/i18n-edge 8.0.0-alpha.0-27579558.fdbd51b Package.json dependencies section is very simple:
"dependencies": {
"@nuxtjs/i18n": "npm:@nuxtjs/i18n-edge"
},
"devDependencies": {
"nuxt": "3.0.0-rc.4"
}
nuxt.config.ts was inspired by your example here https://github.com/nuxt-community/i18n-module/blob/next/playground/nuxt3/nuxt.config.ts
import { defineNuxtConfig } from "nuxt";
export default defineNuxtConfig({
modules: ["@nuxtjs/i18n"],
vite: { build: { minify: false } },
i18n: {
langDir: "locales",
lazy: true,
baseUrl: "http://localhost:3000",
locales: [
{ code: "ru", iso: "ru-RU", file: "ru.json", name: "ru" },
{ code: "en", iso: "en-US", file: "en.json", name: "en" },
],
defaultLocale: "ru",
detectBrowserLanguage: false,
vueI18n: {
legacy: false,
locale: "ru",
fallbackLocale: { ru: ["en"], en: ["ru"] },
},
},
});
I’m using useI18n and useLocalePath composables in pages and components. I’m importing composables like this:
import { useI18n } from "@nuxtjs/i18n/node_modules/@intlify/vue-i18n-bridge";
import { useLocalePath } from "@nuxtjs/i18n/node_modules/vue-i18n-routing";
In your playground example it is not very clear to understand where to import they from. https://github.com/nuxt-community/i18n-module/blob/next/playground/nuxt3/pages/index.vue - here you import they from “#i18n”. I tried to import them from “@nuxtjs/i18n”, but:
Module '"@nuxtjs/i18n"' has no exported member 'useI18n'.
What is the correct way to import them?
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Related StackOverflow Question
It seems to be an ongoing issue at the latest alpha version. Try out this version in your
package.json:This is working for me and I will keep using it until the issue is solved: https://github.com/nuxt-community/i18n-module/issues/1451.
Apparently, the correct way to import those composables is to use
import { useI18n } from "#i18n", as I could find in the examples in https://github.com/nuxt-community/i18n-module/issues/1451. The type recognition seems to be broken and it shows that it can’t find the declarations, but it is still working in dev/prod.