我已经安装了带有npm install firebase
like on documentation的FireBase SDK
package.json个
{
"main": "firebase.js",
"type": "module",
"dependencies": {
"firebase": "^9.15.0"
}
}
firebase.js个
import { initializeApp } from 'firebase/app';
const firebaseConfig = {
//... My apiKey ... etc
};
const app = initializeApp(firebaseConfig);
console.log('DEBUG APP',app);
//until here everything ok I can see the app object
文档的下一步是配置Web凭据:
import { getMessaging, getToken } from "firebase/messaging";
//here got error:
//SyntaxError: The requested module 'firebase/messaging' does not provide an export named 'getToken'
//I tried only import { getMessaging } ... but also not provided
const messaging = getMessaging();
// Add the public key generated from the console here.
getToken(messaging, {vapidKey: "my_wap_public_key_here"});
我也try 过从网页客户端(如文档)
您是否使用ESM并希望使用浏览器模块?替换所有导入行以使用以下模式: 从‘https://www.gstatic.com/firebasejs/9.15.0/firebase-SERVICE.js’导入{} (其中,SERVICE是SDK名称,如Firebase-Firestore).
但如果我试着
import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.15.0/firebase-app.js';
我收到错误Uncaught SyntaxError: Cannot use import statement outside a module