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
Firebase multiple "apps" - client side and server side

So, I wanted to add another firebase app into the project. I already had one for SSR (firebase-admin), so server could pre-render sites. Now I want to add firebase@8, so I can start using it on client side, and later apply firestore rules to it. The problem is, when I'm trying to use it I get this error:

/node_modules/@google-cloud/storage/build/src/bucket.js:22:0
Module not found: Can't resolve 'fs'

Import trace for requested module:
./node_modules/@google-cloud/storage/build/src/index.js
./node_modules/firebase-admin/lib/storage/storage.js
./node_modules/firebase-admin/lib/app/firebase-namespace.js
./node_modules/firebase-admin/lib/default-namespace.js
./node_modules/firebase-admin/lib/index.js
./firebase/config.js
./firebase/createDocument.js
./components/form/Form.js
./pages/opinia/index.js

https://nextjs.org/docs/messages/module-not-found

Here is my config file:

import * as admin from 'firebase-admin';
import firebase from 'firebase';
import 'firebase/firestore';

// initialize firebase on CLIENT
const firebaseConfig = {
  apiKey: process.env.FIREBASE_KEY,
  authDomain: process.env.FIREBASE_DOMAIN,
  projectId: process.env.FIREBASE_ID,
  storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
  messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
  appId: process.env.APP_ID,
};

export const clientApp = initializeApp(firebaseConfig);

// firestore
export const projectFirestoreClient = firebase.firestore(clientApp);

// timestamp
export const timestampClient = firebase.firestore.Timestamp;

// initialize firebase on SERVER
if (!admin.apps.length) {
  const serviceAccount = require('./firebase-adminsdk.json');

  admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
  });
}

// firestore
export const projectFirestoreAdmin = admin.firestore();

// timestamp
export const timestampAdmin = admin.firestore.Timestamp;

So, my question is, how do I fix this error? And what's causing it? Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Firebase Admin is not meant to be used on client side. When you run the app, Firebase Admin is also being imported and causing that error. Ideally you should initialize Firebase Admin in a different file that can be accessed on server side only.

Checkout this blog for step-by-step explanation on how to use Firebase Admin with NextJS.

about 4 years ago · Juan Pablo Isaza Report
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!