title: Using Environment Variables in nuxt.config.js
body: <p>I'm using Nuxt &amp; Axios but having trouble using environment variables when <strong>building</strong> the application from my <strong>local machine</strong>. </p>
  
  <p>I have installed the @nuxtjs/dotenv module in an attempt to fix this issue but still having problems.</p>
  
  <p>Note: The environment variables work fine when building the app within my hosting providers environment. It is only building from my local machine that gives me trouble. My IDE is VS Code.</p>
  
  <p>Here is my axios setup inside nuxt.config.js:</p>
  
  <pre><code>module.exports = {
    ...
    buildModules: [
      '@nuxtjs/dotenv'
    ],
    modules: [
      // Doc: https://axios.nuxtjs.org/usage
      '@nuxtjs/axios'
    ],
    axios: {
      baseURL: process.env.BASE_URL
    },
    ...
  }
  </code></pre>
  
  <p>My .env file has the following:</p>
  
  <pre><code>BASE_URL="https://some.api.com"
  </code></pre>
  
  <p>The .env variables are not being recognized when building the app:</p>
  
  <pre><code>nuxt build
  </code></pre>
  
  <p>Instead, it just sets the axios base url to the same host:port that the server runs on by default. Ex: localhost:4000</p>
  
  <p>I found the following documentation from @nuxtjs/dotenv module: <a href="https://github.com/nuxt-community/dotenv-module#using-env-file-in-nuxtconfigjs" rel="noreferrer">https://github.com/nuxt-community/dotenv-module#using-env-file-in-nuxtconfigjs</a>. This instructs you to add the following to the top of nuxt.config.js: </p>
  
  <pre><code>require('dotenv').config()
  </code></pre>
  
  <p>This works for building locally; my variables from .env are recognized! However, because dotenv is a dev dependency, this causes the build to crash when deployed to my hosting provider because the module isn't recognized.</p>
  
  <p>I know that I can define the environment variables directly in the build command as follows but <strong>I would prefer NOT to do so</strong>:</p>
  
  <pre><code>NUXT_ENV_BASE_URL=some.api.com nuxt build 
  </code></pre>
  
  <p>Is there an easy way to get environment variables to work locally inside of nuxt.config.js during the build process that also works well when deploying to production??</p>
  
  <p>Thank you!</p>