title: Firebase messaging ServieWorkerGlobalScope error on init
body: <p>I am trying to connect to the firebase db and create a class for messaging but for some reason I get <code>ReferenceError: self is not defined</code> when initializing the fireabase app.</p>
  
  <pre><code>import app from "firebase/app";
  import "firebase/messaging";
  
  const options = {
      apiKey: process.env.FIREBASE_API_KEY,
      authDomain: process.env.FIREBASE_AUTH_DOMAIN,
      databaseURL: process.env.FIREBASE_DATABASE_URL,
      projectId: process.env.FIREBASE_PROJECT_ID,
      storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
      messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID
  };
  
  class Firebase {
      constructor() {
          app.initializeApp(options);
  
          this.messaging = app.messaging();
      }
  }
  
  const FirebaseApp = new Firebase();
  
  export default FirebaseApp;
  </code></pre>
  
  <p>Full error is as follows:</p>
  
  <pre><code>/node_modules/@firebase/messaging/dist/index.cjs.js:2110
  if (self &amp;&amp; 'ServiceWorkerGlobalScope' in self) {
  ^
  ReferenceError: self is not defined
  </code></pre>
  
  <p>If I remove <code>this.messaging=...</code> from <code>constructor()</code> then the error goes away.</p>