Firebase getToken - 无法解构 属性 'appConfig'

Firebase getToken - Cannot destructure property 'appConfig'

我有以下简单的消息传递应用程序

// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getMessaging, getToken } from "firebase/messaging";

// Your web app's Firebase configuration
const firebaseConfig = {
  apiKey: "AI...Y",
  authDomain: "xyz.firebaseapp.com",
  databaseURL: "https://xyz.firebaseio.com",
  projectId: "xyz",
  storageBucket: "xyz.appspot.com",
  messagingSenderId: "441...38",
  appId: "1:....f",
  measurementId: "G-...",
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);

const vapidKey = "BLFWI5-...opE";

console.log("have app");
const messaging = getMessaging(app);

console.log("have messaging", messaging);
getToken({ vapidKey })
  .then((res) => console.log("token", res))
  .catch((err) => console.error(err));

haveApphaveMessaging 似乎正确记录,但我最终在 getToken.catch

TypeError: Cannot destructure property 'appConfig' of 'undefined' as it is undefined.
    at getKey2 (idb-manager.ts:104:19)
    at dbGet (idb-manager.ts:50:15)
    at getTokenInternal (token-manager.ts:52:30)

我实际上有一个复杂得多的应用程序,它使用类似的设置,但我想回到基础知识来检查我是否理解一些基本知识。任何想法。

我已经尝试使用 VSCode 的内置服务器使用 CDN 导入,现在 vite 使用本地导入。错误始终是相同的消息,尽管具有不同的堆栈跟踪

使用 v9?您需要将 Messaging 实例作为第一个参数传递...

getToken(messaging, { vapidKey })

https://firebase.google.com/docs/reference/js/messaging_.md#gettoken

Signature:

export declare function getToken(messaging: Messaging, options?: GetTokenOptions): Promise<string>;

这是版本 8 和版本 9 之间的主要变化之一。您从各种库导入的所有函数都需要传入 FirebaseApp 或其他实例。