Firebase: No Firebase App '[DEFAULT]' has been created in React app

Hey guys, I’m trying to set up push notifications, starting with web. I’m following this guide

and this guide

I’ve setup firebase and followed all the steps, but I’m not getting past this point:
When requesting a token from firebase

const {token} = await FirebaseMessaging.getToken(options);

I’m getting this error:

Firebase: No Firebase App '[DEFAULT]' has been created - call initializeApp() first (app/no-app).

I’ve installed the following package.json:

    "@capacitor-firebase/messaging": "^5.0.0",
    "@capacitor/core": "^5.0.3",
    "firebase": "^9.22.1",

The errors say call initializeApp first. But I’m definitly calling initializeApp() first… Perhaps not in the right way or place? The guide is for angular, so I’m trying to make it work for React. Below is a simplified setup without any components. Just calling initialize and then trying to get a token.

import {Capacitor} from '@capacitor/core';
import {initializeApp} from 'firebase/app';
import {FirebaseMessaging,GetTokenOptions} from '@capacitor-firebase/messaging';

export async function requestPermissions() {
  await FirebaseMessaging.requestPermissions();

export async function getTokenFirebase() {
  const options: GetTokenOptions = {
    vapidKey: '',
  if (Capacitor.getPlatform() === 'web') {
    options.serviceWorkerRegistration = await navigator.serviceWorker.register('firebase-messaging-sw.js');
  const {token} = await FirebaseMessaging.getToken(options);

  console.log('getToken', token);
  return token;

const initializeFirebase = () => {
  if (Capacitor.isNativePlatform()) {
  return initializeApp({
    apiKey: '',
    authDomain: '',
    projectId: '',
    storageBucket: '',
    messagingSenderId: '',
    appId: '',
    measurementId: '',
//initialize firebase right at the start when the app starts up
let app = initializeFirebase();
console.log('Firebase initialized',app);
getTokenFirebase().then((token) => {

The logs show that firebase is initialised with an app

If anyone has a better guide that I can follow / example setup / knows how to get past this error, help is much appreciated as I’ve been stuck on this for a while now.