My vue application is not loading environment variables properly.
I have the dotenv library in package.json.
.env.development
has VITE_BACKEND_URL=http://localhost:3000
and one of my pinia files uses the VITE_BACKEND_URL environment variable. I added a console.log in the file to check the content of the variable.
const BACKEND_URL = import.meta.env.VITE_BACKEND_URL
console.log('BACKEND_URL 1', BACKEND_URL)
the console.log
returns BACKEND_URL 1 undefined
.
I started my rails server with RAILS_ENV=development rails s
.
My application is a headless project. I have a frontend
folder at the root level of my application. The .env
files have to be located at the root of the frontend
folder, not the root of the whole project.