0

My .env (or .env.local):

apiURL=https://<dev-url>

My nuxt.config.js

publicRuntimeConfig: {
  apiURL: process.env.NODE_ENV === 'production'
    ? 'https://<prod-url>'
    : process.env.apiURL
},
proxy: {
  '/api_vue': {
    target: process.env.apiURL,
    changeOrigin: true
  }
},

Everything works well until I add .local to .env.
Nuxt says:

Error: [HPM] Missing "target" option. Example: {target: │
nuxt-app | │ "http://www.example.org"}

kissu
  • 40,416
  • 14
  • 65
  • 133
forever_young
  • 131
  • 1
  • 7
  • Can you try that one? https://stackoverflow.com/a/68338032/8816585 Also, do you only want to have a `.local.env`? Isn't it supposed to be `.env.local` (local should be a suffix AFAIK)? Also, what happens if you have a combo of: `.env` + `.env.local`? I'm not even sure that this is recommended anyway: https://github.com/motdotla/dotenv#should-i-have-multiple-env-files – kissu May 30 '22 at 19:42

1 Answers1

0

You should import dotenv to load .env variables.

require("dotenv").config()

I also recommend to rename your .env variables to the following format:

apiURL --> API_URL
kissu
  • 40,416
  • 14
  • 65
  • 133
Craws
  • 576
  • 4
  • 30