title: Firebase Modular SDK V9.0.0+ TypeError: Cannot read property 'apps' of undefined firebase
body: <p>I got this error when trying to run my next.js app. I try lots of ways but I can't solve this. I am using firebase 9.0.1</p>
  <pre><code>Server Error
  TypeError: Cannot read property 'apps' of undefined
  
  This error happened while generating the page. Any console logs will be displayed in the terminal window.
  Source
  .next\server\pages\_app.js (14:13) @ Object../firebase.js
  
    12 | };
    13 |
  &gt; 14 | const app = !firebase.apps.length
       |             ^
    15 |   ? firebase.initializeApp(firebaseConfig)
    16 |   : firebase.app();
  </code></pre>
  <p>Here is my firebase.js</p>
  <pre class="lang-js prettyprint-override"><code>import firebase from &quot;firebase/app&quot;;
  
  // For Firebase JS SDK v7.20.0 and later, measurementId is optional
  const firebaseConfig = {
    apiKey: &quot;&quot;,
    authDomain: &quot;&quot;,
    projectId: &quot;&quot;,
    storageBucket: &quot;&quot;,
    messagingSenderId: &quot;&quot;,
    appId: &quot;&quot;,
    measurementId: &quot;&quot;
  };
  
  const app = !firebase.apps.length
    ? firebase.initializeApp(firebaseConfig)
    : firebase.app();
  
  const db = app.firestore();
  const auth = app.auth();
  const provider = new firebase.auth.GoogleAuthProvider();
  
  export { db, auth, provider };
  </code></pre>