Preloader
Vue.js 2
  • Estimated reading time: 1 Minute

How to fix Vue I18n Uncaught TypeError: Cannot read property 'config' of undefined

How to fix Vue I18n Uncaught TypeError: Cannot read property 'config' of undefined

I've been working on a Vue.js app that needs to be localized in multiple languages. For Vue.js, the best module to implement i18n is Vue.js I18N. After the installation, I tried to initialize it just as described in the documentation, however, I missed something out in my code and ended up with this exception: Uncaught TypeError: Cannot read property 'config' of undefined.

The following code will trigger the mentioned exception in any Vue app:

// main.js
// Example of regular VueJS app with translation
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

// 1. Import i18n
import VueI18n from 'vue-i18n';

// 2. Create VueI18n instance with options
const i18n = new VueI18n({
    // set locale
    locale: 'en',
    // set locale messages
    messages: {
        en: {
            message: {
                hello: 'hello world'
            }
        },
        ja: {
            message: {
                hello: 'こんにちは、世界'
            }
        }
    }
});

Vue.config.productionTip = false;

new Vue({
    router,
    store,
    i18n,
    render: h => h(App)
}).$mount("#app");

If you are facing the same exception, you are probably doing the same with the code. You import the i18n module, create a new instance and inject it to the Vue instance. However, you forgot to instruct Vue.js to use the new module. To fix this error, simply indicate that Vue should use the the Vue I18N module before creating the instance like this:

// 1. Import the library
import VueI18n from 'vue-i18n'

// 2. Important! Just right before initializing the I18n instance, use the module
Vue.use(VueI18n)

// 3. Create I18n instance
const i18n = new VueI18n({
    // ...
});

// 4. Load into vue
new Vue({
    i18n,
    render: h => h(App)
}).$mount("#app");

The final code without this tedious exception will look like this:

// main.js
// Example of regular VueJS app with translation
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

// 1. Import i18n
import VueI18n from 'vue-i18n';

// 2. Just right before initializating the I18n instance, use the module
Vue.use(VueI18n)

// 3. Create VueI18n instance with options
const i18n = new VueI18n({
    // set locale
    locale: 'en',
    // set locale messages
    messages: {
        en: {
            message: {
                hello: 'hello world'
            }
        },
        ja: {
            message: {
                hello: 'こんにちは、世界'
            }
        }
    }
});

Vue.config.productionTip = false;

new Vue({
    router,
    store,
    i18n,
    render: h => h(App)
}).$mount("#app");

Happy coding ❤️!

Share:
Carlos Delgado

Carlos Delgado

Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Related articles
How to use a button as a file uploader with Vuetify in Vue.js
28 Oct, 2021
  • Estimated reading time: 1 Minute
What's the equivalent to optgroup selects in Vuetify
3 Aug, 2021
  • Estimated reading time: 1 Minute
How to use Web Workers in Vue.js
27 Jul, 2021
  • Estimated reading time: 7 Minutes
How to disable swiping on Vuetify Tabs
27 Jul, 2021
  • Estimated reading time: 1 Minute
How to disable the prefetch plugin in Vue.js 2
21 Jul, 2021
  • Estimated reading time: 12 Minutes
How to copy text to the clipboard in Vue.js 2
16 Dec, 2020
  • Estimated reading time: 2 Minutes
Weekly trending
What Makes a Portable Power Station Worth the Investment?
17 Jun, 2026
  • Estimated reading time: 4 Minutes
Building a Modern Lead Generation Workflow With Public Social Data
17 Jun, 2026
  • Estimated reading time: 3 Minutes
Best Instant Crypto Exchange for Lazy Investors
17 Jun, 2026
  • Estimated reading time: 6 Minutes
Our Sponsors

Our blog is proudly supported by industry-leading sponsors.