Vue application served by vite is not loading environment variables from .env files located at the root of the project, backend is rails-api

  Kiến thức lập trình

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.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website Kho Theme wordpress Kho Theme WP Theme WP

LEAVE A COMMENT