loading env variables in react app using vite

The environment variable name used in code must match the name set in the .env file:

// .env
VITE_API_KEY=abcd1234
   👆
// firebase.js
const firebaseConfig = {      👇
  apiKey: import.meta.env.VITE_API_KEY,
  â‹®
}

demo

Relevant documentation can be found in the Vite Env variables docs

Leave a Comment