{"id":10894,"library":"firebase","title":"Firebase JavaScript SDK","description":"The Firebase JavaScript SDK provides a comprehensive client-side library for interacting with Google's Firebase platform, suitable for web, mobile-web (e.g., React Native, Ionic), and Node.js desktop (e.g., Electron) applications. The current stable version is 12.12.0, with minor versions released frequently, often weekly or bi-weekly, reflecting continuous development and updates across its sub-packages. It offers a suite of services including Authentication, Cloud Firestore, Realtime Database, Cloud Storage, Cloud Functions, Messaging, Performance Monitoring, Analytics, Remote Config, App Check, and AI capabilities. A key differentiator since version 9 is its modular, tree-shakable API, which significantly improves application bundle sizes. This SDK is distinct from the Firebase Admin Node.js SDK, which is designed for privileged server environments and administrative access.","status":"active","version":"12.12.0","language":"javascript","source_language":"en","source_url":"https://github.com/firebase/firebase-js-sdk","tags":["javascript","authentication","database","Firebase","firebase","realtime","storage","performance","remote-config","typescript"],"install":[{"cmd":"npm install firebase","lang":"bash","label":"npm"},{"cmd":"yarn add firebase","lang":"bash","label":"yarn"},{"cmd":"pnpm add firebase","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for Firebase Auth in React Native environments, requiring v2+","package":"react-native-async-storage","optional":false}],"imports":[{"note":"Since v9, Firebase uses a modular API for tree-shaking. Import specific functions from service modules, not the top-level 'firebase' package directly for services.","wrong":"const firebase = require('firebase/app');\nimport firebase from 'firebase';","symbol":"initializeApp","correct":"import { initializeApp } from 'firebase/app';"},{"note":"Individual service functions like `getAuth()` are imported from their respective modular paths. The compat API (e.g., `firebase/compat/auth`) still exists but is not tree-shakable.","wrong":"import firebase from 'firebase/auth'; // Incorrect modular import\nimport { auth } from 'firebase'; // Old compat API pattern","symbol":"getAuth","correct":"import { getAuth, signInWithEmailAndPassword } from 'firebase/auth';"},{"note":"Follow the modular pattern for all services. Each service (Firestore, Realtime Database, Storage, etc.) has its own entry point.","wrong":"const firestore = require('firebase/firestore').firestore; // CommonJS with modular API\nimport { firestore } from 'firebase'; // Old compat API pattern","symbol":"getFirestore","correct":"import { getFirestore, collection, addDoc } from 'firebase/firestore';"},{"note":"TypeScript types for various Firebase objects are available directly from the service modules.","symbol":"Auth types","correct":"import type { User } from 'firebase/auth';"}],"quickstart":{"code":"import { initializeApp } from 'firebase/app';\nimport { getFirestore, collection, addDoc } from 'firebase/firestore';\n\n// TODO: Replace the following with your app's Firebase project configuration\nconst firebaseConfig = {\n  apiKey: \"YOUR_API_KEY\",\n  authDomain: \"YOUR_PROJECT_ID.firebaseapp.com\",\n  projectId: \"YOUR_PROJECT_ID\",\n  storageBucket: \"YOUR_PROJECT_ID.appspot.com\",\n  messagingSenderId: \"YOUR_MESSAGING_SENDER_ID\",\n  appId: \"YOUR_APP_ID\",\n  // Optional: measurementId: \"G-XXXXXXXXXX\"\n};\n\nasync function initializeAndAddData() {\n  try {\n    const app = initializeApp(firebaseConfig);\n    console.log(\"Firebase app initialized successfully.\");\n\n    const db = getFirestore(app);\n    const docRef = await addDoc(collection(db, \"users\"), {\n      first: \"Ada\",\n      last: \"Lovelace\",\n      born: 1815\n    });\n    console.log(\"Document written with ID: \", docRef.id);\n  } catch (error: any) {\n    console.error(\"Error initializing Firebase or adding document:\", error.message);\n  }\n}\n\ninitializeAndAddData();\n","lang":"typescript","description":"Initializes a Firebase app and demonstrates adding a document to Cloud Firestore using the modular API."},"warnings":[{"fix":"Migrate your application to the modular API by importing specific functions from service modules (e.g., 'firebase/app', 'firebase/auth') and using functional patterns (e.g., getAuth(), signInWithEmailAndPassword()). Refer to the Firebase 'Upgrade to Version 9' guide.","message":"Version 9 introduced a completely redesigned modular API to enable tree-shaking and reduce bundle sizes. The previous 'compat' API still works but is not tree-shakable.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Users of `@firebase/ai` should plan to migrate their applications to alternative AI models or services by June 2026. Consult Firebase documentation for recommended replacements.","message":"All Imagen models provided by the `@firebase/ai` package are officially deprecated and will be shut down as early as June 2026.","severity":"deprecated","affected_versions":">=12.11.0"},{"fix":"Instead of the deprecated methods, use the new methods that have been added to the `LiveSession` class for streaming media. Review the `@firebase/ai` changelog for the specific new API.","message":"The `sendMediaChunks()` and `sendMediaStream()` methods within the `@firebase/ai` package's `LiveSession` class have been deprecated.","severity":"deprecated","affected_versions":">=12.5.0"},{"fix":"Ensure `react-native-async-storage` is installed and updated to version 2 or higher in your React Native project when using Firebase Auth. Run `npm install --save react-native-async-storage@^2.0.0` or `yarn add react-native-async-storage@^2.0.0`.","message":"Firebase Authentication for React Native now requires `react-native-async-storage` v2+ as a peer dependency, which may require an update to your `package.json`.","severity":"gotcha","affected_versions":">=12.7.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `initializeApp(firebaseConfig)` is called once at the start of your application's lifecycle before any Firebase service-specific functions are invoked. This call should typically be near your app's entry point.","cause":"Attempting to use a Firebase service (e.g., getAuth(), getFirestore()) before `initializeApp()` has been successfully called.","error":"Firebase: No Firebase App '[DEFAULT]' has been created - call initializeApp() first (app/no-app)."},{"fix":"Verify that your import statements are correct for the modular API (e.g., `import { getAuth } from 'firebase/auth';`). If you intend to use the compat API, explicitly import from `firebase/compat/auth`.","cause":"This error occurs when a bundler or runtime cannot find the expected modular entry point, often due to an incorrect import path or mixing modular imports with the older 'compat' API usage.","error":"Error: Modular code path not found for firebase/auth. Did you mean firebase/compat/auth?"},{"fix":"Switch all Firebase imports to the ES Module syntax (e.g., `import { initializeApp } from 'firebase/app';`). Ensure your bundler configuration (e.g., Webpack, Rollup, Vite) is correctly set up to handle ESM.","cause":"This Webpack-specific error (or similar from other bundlers) often arises when using `require('firebase/app')` or an older CommonJS pattern in a project configured for ES Modules (ESM) with the modern Firebase SDK.","error":"TypeError: __webpack_require__.i(...) is not a function"}],"ecosystem":"npm"}