Vue js not able to get config value

Asked by At

console.log(process.env.test); prints undefined.

I have below config in my dev.env.js file. Is there anything I am missing?

'use strict'
const merge = require('webpack-merge')
const prodEnv = require('./prod.env')

module.exports = merge(prodEnv, {
  NODE_ENV: '"development"',
  TEST: '"http://localhost/api"'
})

1 Answers

1
Ulysse BN On Best Solutions

If you are using the latest VueJS, you should prefix your ENV variables with VUE_APP_. See the documentation.

'use strict'
const merge = require('webpack-merge')
const prodEnv = require('./prod.env')

module.exports = merge(prodEnv, {
  NODE_ENV: '"development"',
  VUE_APP_TEST: '"http://localhost/api"'
})

Also, note that NODE_ENV and BASE_URL are the two exceptions for this rule.