I set in nuxt.config.js env variables
env: {
language: process.env.NODE_LOCALE
},
and after, when plugin code runs in server I get undefined.
import Vue from 'vue'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
export default ({ app, isServer, env }) => {
app.i18n = new VueI18n({
locale: env.language || 'en', #env.language === undefined
fallbackLocale: env.language || 'en',
messages: {
'en': require('~/locales/en.json'),
'es': require('~/locales/es.json'),
'fr': require('~/locales/fr.json'),
'de': require('~/locales/de.json')
}
})
I read doc several times but I can't find a solution.
Edit(more info):
On my laptop(mac) works fine in dev and production mode, but in ubuntu 14.04 server is where stops working.
Edit2:
I found my mistake, I wasn't exporting correctly variables before build. Please close the issue and sorry for the inconvenience.
@keldorg you can close it yourself ! ;)
Hey, I'm having the same issue, could you let me know how you exported the variables correctly? It's not working in dev or production mode either for me though.
Not sure I understand, does that mean you don't make use of the process.env object? Could you maybe show me your nuxt.config.js file?
I use process.env in nuxt.config.js, but if you dont't export variables before launch, the variables will be null.
env: {
locale: process.env.NODE_LOCALE || 'en',
domain: process.env.NODE_DOMAIN || 'com'
},
In nuxtjs web page is well explained:
https://nuxtjs.org/api/configuration-env
Right I think I understand, are you exporting the variables in the config files itself too then?
@keldorg I'm having same issue, when repeating what the docs say, it doesn't work. My nuxt.config.js file has an env object with keys and values and yet none of them are accessible in my plugins
@glensargent are you exporting variables correctly? My fault was that I wasn't exporting before build.
@keldorg could you show me an example of how you're exporting and where?
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
@keldorg could you show me an example of how you're exporting and where?