question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue.locale is not a function - Issue after upgrading to 3.0

See original GitHub issue

I’m getting Unknown TypeError: Vue.locale is not a function

var VueI18n = require('vue-i18n')

Vue.use(VueI18n)
Vue.config.lang = 'sv'
var locales = require('./lang/locales')

Object.keys(locales).forEach(function (lang) {
  Vue.locale(lang, locales[lang])
})

And in my locales file I have like I had in 2.*:

module.exports = {
  en: {
    message: 'Hi',
  },
  sv: {
    message: 'Hej',
  }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:28 (6 by maintainers)

github_iconTop GitHub Comments

39reactions
alexcrooxcommented, Mar 4, 2017

Can confirm, npm install vue-i18n is installing "^6.0.0-alpha.2" which is triggering the error

Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_0_vue___default.a.locale is not a function when following the getting started guide exactly (setting up before initiating vue-router etc)

The error goes away if I manually force in package.json "vue-i18n": "^5.0.3"

6reactions
peterthomashorncommented, Jul 22, 2016

I have the same issue (vue-i18n@^4.0.1) but I do not use vue-router. It is just Vue.js and a custom component. This is my script:

import Vue  from 'vue';
import Search from './search.vue';
import VueI18n from 'vue-i18n';

$(document).foundation();

var locales = {
    de: {
        labels: {
            fairs: "Messen"
        }
    },
    en: {
        labels: {
            fairs: "Fairs"
        }
    }
};

Vue.use(VueI18n);

var documentLanguage = $('html').attr('lang');

Vue.config.lang = documentLanguage;

Object.keys(locales).forEach(function (lang) {
    Vue.locale(lang, locales[lang]);
});

The line setting the locale strings (Vue.locale(lang, locales[lang]);) results in the error _coboo-4a6b9317b0.js:11410 Uncaught TypeError: vue2.default.locale is not a function. Browserify compiles it to:

var _vue = require('vue');
var _vue2 = _interopRequireDefault(_vue);
var _search = require('./search.vue');
var _search2 = _interopRequireDefault(_search);
var _vueI18n = require('vue-i18n');
var _vueI18n2 = _interopRequireDefault(_vueI18n);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

$(document).foundation();

var locales = {
    de: {
        labels: {
            fairs: "Messen"
        }
    },
    en: {
        labels: {
            fairs: "Fairs"
        }
    }
};

_vue2.default.use(_vueI18n2.default);
var documentLanguage = $('html').attr('lang');
_vue2.default.config.lang = documentLanguage;

Object.keys(locales).forEach(function (lang) {
    _vue2.default.locale(lang, locales[lang]);
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

vue.js - _vue2.default.locale is not a function - Stack Overflow
When I used vue-i18n in my project ...
Read more >
Frequently asked questions — Vuetify
When will Vuetify v3 be released? Why is Search Vuetify not working properly? My application won't compile due to sass / scss errors....
Read more >
The Ultimate Vue Localization Guide | Phrase
Dive into Vue localization and learn how to plug the Vue I18n library into your app, so you can make it accessible to...
Read more >
Single file components | Vue I18n
If you are building Vue component or Vue application using single file components, you can manage the locale messages i18n custom block.
Read more >
Localization - VeeValidate
If you have multiple locales in your app, loading all the validation messages for those locales is not optimal. You can load a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found