Vue-i18n 'Cannot read property '_t' of undefined at Proxy.Vue.$t' Vue-i18n 'Cannot read property '_t' of undefined at Proxy.Vue.$t' vue.js vue.js

Vue-i18n 'Cannot read property '_t' of undefined at Proxy.Vue.$t'


Ah, embarrassingly simple, I changed

import i18n from './plugins/i18n'

to

import {i18n} from './plugins/i18n'

and all works now.


If anyone came here with the same issue, but is using export default, I had this in my main.js:

import translations from './translations';new Vue({    translations,    ...}).$mount('#app');

Where translations/index.js loaded the plugin and everything like normal. Apparently you have to name the import 'i18n' for this to work correctly:

import i18n from './translations';new Vue({    i18n,    ...}).$mount('#app');


src/i18n/index.js

import Vue from 'vue'import VueI18n from 'vue-i18n'Vue.use(VueI18n)// 注册i18n实例并引入语言文件const i18n = new VueI18n({  locale: 'zh_cn',  messages: {    'zh_cn': require('@/assets/languages/zh_cn.json'),    'en_us': require('@/assets/languages/en_us.json'),    'es_ve': require('@/assets/languages/es-ve.json')  }})export default i18n

main.js

import i18n from '@/i18n'new Vue({  i18n,  router,  render: h => h(App)}).$mount('#app')