简体   繁体   English

未捕获的类型错误:firebase.messaging 不是函数

[英]Uncaught TypeError: firebase.messaging is not a function

Here is my code:这是我的代码:

    <script>

        // Your web app's Firebase configuration
        var firebaseConfig = {
            apiKey: "<from firebase>",
            authDomain: "<from firebase>",
            databaseURL: "<from firebase>",
            projectId: "<from firebase>",
            storageBucket: "",
            messagingSenderId: "<from firebase>",
            appId: "<from firebase>"
        };
        // Initialize Firebase
        firebase.initializeApp(firebaseConfig);


        // [START get_messaging_object]
        // Retrieve Firebase Messaging object.
        const messaging = firebase.messaging();

    </script>

This line firebase.messaging();这一行firebase.messaging(); throws:抛出:

Uncaught TypeError: firebase.messaging is not a function at Uncaught TypeError: firebase.messaging is not a function at

Noted that the result of console.log(firebase) is:注意到console.log(firebase)的结果是:

在此处输入图片说明

Any idea what's the problem?知道有什么问题吗?

It looks like you didn't follow the basic integration steps from the documentation.看起来您没有遵循文档中的基本集成步骤。 There is an include for messaging:有一个用于消息传递的包含:

<script src="https://www.gstatic.com/firebasejs/7.7.0/firebase-messaging.js"></script>

You must included import '@firebase/messaging' for it to work.您必须包含 import '@firebase/messaging' 才能使其工作。 So it's supposed to look like this:所以它应该是这样的:

import * as firebase from 'firebase/app';
import '@firebase/messaging';

Original answerd: TypeError: firebase.messaging is not a function in node.js原回答: TypeError: firebase.messaging is not a function in node.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:firebase.messaging 不是 node.js 中的函数 - TypeError: firebase.messaging is not a function in node.js Firebase云消息传递-调用firebase.messaging()时出错 - Firebase Cloud Messaging - Error calling firebase.messaging() firebase.messaging:无法读取未定义的属性“getNotificationPermission_” - firebase.messaging: Cannot read property 'getNotificationPermission_' of undefined Web firebase.messaging().onMessage 未触发,但后台通知完美触发 - Web firebase.messaging().onMessage not fired, but background notification perfectly fired 每次刷新使用Firebase Cloud Messaging + React和firebase.messaging()。getToken()都是不同的 - Using Firebase Cloud Messaging + React and firebase.messaging().getToken() is different each refresh Firebase“未捕获的类型错误:myDataRef.push 不是函数” - Firebase "Uncaught TypeError: myDataRef.push is not a function" 未捕获的类型错误:firebase.database 不是 function - Uncaught TypeError: firebase.database is not a function 未捕获的TypeError:(0,_firebase.auth)不是函数 - Uncaught TypeError: (0 , _firebase.auth) is not a function 未捕获的类型错误:firebase.auth 不是函数 - Uncaught TypeError: firebase.auth is not a function Firebase上的“未捕获的TypeError:未定义不是函数”错误 - “Uncaught TypeError: undefined is not a function” error on firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM