VueJs ,Vue.use(VueI18n) or app.use(VueI18n) TypeError: Cannot read properties of undefined (reading 'use')

Viewed 24

I use VueI18n but i have an error: TypeError: Cannot read properties of undefined (reading 'use') How con i solve this error? Thnx?

import VueI18n from 'vue-i18n';
import { languages } from './i18n/index.js';
app.use(VueI18n);//here i have error

let locale = 'it';

const messages = Object.assign(languages);

export const i18n = new VueI18n({

locale: locale,

fallbackLocale: 'it',

messages,

i18n

});

2 Answers

Where and what is your 'app'?
You can try this:

import { createApp } from 'vue'
const app = createApp({})

or

import { createApp } from 'vue'
import App from './App.vue'
const app = createApp(App)

then

app.use(VueI18n)

you have to create the application before using it :

main :

import App from './App.vue';
import VueI18n from 'vue-i18n';

const app = createApp(App);
app.use(VueI18n);
Related