Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
Not able to initialize firebase app using the env variable

I am working on a next js project. I want to use firestore in my project. So as the process I am initializing firebase app and firestore in one of my file and using them in another service file. But If I use env variable to initialize my firebase app, then it's not working.

Here is my project file structure:
enter image description here

On firebase/firebaseClient.js, I am initializing my firebase app. If I use the value directly then it's working. If I use env variable then It's not working.

firebase/firebaseClient.js:

// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";

// This not working. Value in the env file is the same
const firebaseConfig = {
  apiKey: process.env.FIREBASE_CLIENT_API_KEY,
  authDomain: process.env.FIREBASE_CLIENT_AUTH_DOMAIN,
  projectId: process.env.FIREBASE_CLIENT_PROJECT_ID,
  storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
  messagingSenderId: process.env.FIREBASE_CLIENT_MESSAGIN_SENDER_ID,
  appId: process.env.FIREBASE_APP_ID,
  measurementId: process.env.FIREBASE_CLIENT_MEASUREMENT_ID,
};

// This is working
const firebaseConfig = {
  apiKey: "MY_API_KEY",
  authDomain: "MY_AUTHDOMAIN",
  projectId: "MY_PROJECT_ID",
  storageBucket: "MY_STORAGE_BUCKET",
  messagingSenderId: "MY_MESSAGIN_SENDER_ID",
  appId: "MY_APP_ID",
  measurementId: "MY_MEASUREMENT_ID",
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
export const db = getFirestore(app);

And then in service/appContent.js I am fetching data using this code:

import { initializeApp } from "firebase/app";
import { collection, getDocs } from "firebase/firestore";
import { db } from "../firebase/firebaseClient";

export const getAppContent = async () => {
  const contentQuery = collection(db, "/shop/app-design/content");
  const contentData = await getDocs(contentQuery);
  const data = contentData.docs.map((doc) => doc.data());
  return data;
};

When using env variable to initialize firebase app, I am getting this error:
enter image description here

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!