Firebase函数无法在应用程序中使用调用函数,返回内部错误 [英] Firebase Functions not able to use oncall functions in app, returns internal error

查看:29
本文介绍了Firebase函数无法在应用程序中使用调用函数,返回内部错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困在firebase函数部分中,首先我什至无法部署它们,因为在我的帐户中启用了计费,然后我将package.json中的节点版本设置为'8',但没有部署这些功能时要求收费.

And I got stuck in the firebase functions part, first I was not even able to deploy them because billing was enabled in my account, then I put the node version in the package.json to '8', it didn't ask for billing when I deployed the functions.

package.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "main": "index.js",
  "dependencies": {
    "firebase-admin": "^8.10.0",
    "firebase-functions": "^3.6.1"
  },
  "devDependencies": {
    "eslint": "^5.12.0",
    "eslint-plugin-promise": "^4.0.1",
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}

之前是 "node": "10"

此后,我可以部署功能,甚至运行 onRequest 功能,但不能运行 onCall 功能. 每当我尝试调用 onCall 函数时,我都不知道会发生什么,也许我会收到不确定的错误消息.

After this, I'm able to deploy the functions and even run an onRequest function, but not the onCall function. Whenever I try to call an onCall function, I don't know what happens, maybe I get an error I'm not sure.

index.js firebase函数文件

index.js firebase function file

const functions = require('firebase-functions');

exports.randomNumber = functions.https.onRequest((request, response) => {
    const number = Math.round(Math.random() * 100);
    console.log(number);
    response.send(number.toString());
});

exports.sayHello = functions.https.onCall((data, context) => {
    console.log('its running');
    return 'hello, ninjas';
});

randomNumber 运行完美,但是 sayHello 从未运行. 我正在从前端调用 sayHello 函数

The randomNumber runs perfectly, but sayHello never runs or whatever. I'm calling the sayHello function from frontend

app.js 我的网络应用的javascript文件

app.js my web app's javascript file

//sayHello function call
const button = document.querySelector('.call');
button.addEventListener('click', () => {
    //get firebase function reference
    const sayHello = firebase.functions().httpsCallable('sayHello');
    sayHello().then(result => {
        console.log(result.data);
    }).catch(error => {
        console.log(error);
    });
});

我也在index.html中正确初始化firebase

I'm also initializing firebase properly in the index.html

<!-- The core Firebase JS SDK is always required and must be listed first -->
    <script src="/__/firebase/7.21.1/firebase-app.js"></script>
    <!-- include only the Firebase features as you need -->
    <script src="/__/firebase/7.21.1/firebase-auth.js"></script>
    <script src="/__/firebase/7.21.1/firebase-firestore.js"></script>
    <script src="/__/firebase/7.21.1/firebase-functions.js"></script>

    <!-- Initialize Firebase -->
    <script src="/__/firebase/init.js"></script>

在我的Web应用程序的控制台中,记录了一些内容

In the console of my web app, something gets logged

Error: internal
    at new y (error.ts:66)
    at w (error.ts:175)
    at A.<anonymous> (service.ts:245)
    at tslib.es6.js:100
    at Object.next (tslib.es6.js:81)
    at r (tslib.es6.js:71)

任何人都至少可以说出此控制台日志的含义吗???


请帮忙,由于无法完成本系列教程,在此之前我将继续进行一些实际的项目,现在已经停滞了一周. 预先感谢,如果可以解决我的问题.

Can anyone at least tell what this console log means???


Please help, not able to complete the tutorial series after which I'll move on to some real projects, been stuck at this for a week now. Thanks in advance, if can solve my problem.

只需将您在前端使用的javascript sdk版本降级到7.21.0,就可以了.

Just downgrade the javascript sdk version you are using in your front end to 7.21.0, that's it, it'll work.

问题由 @DougStevenson 如下所述,Firebase可调用函数当前(2020年10月)不适用于javascript sdk 7.21.1和7.22.0.

The issue was as stated by @DougStevenson below that Firebase callable functions, at the current time (Oct 2020) is not working with javascript sdk 7.21.1 and 7.22.0.

升级到Firebase 7.22.0后无法再调用HttpsCallable函数

<!-- The core Firebase JS SDK is always required and must be listed first -->
    <script src="/__/firebase/7.21.0/firebase-app.js"></script>
    <!-- include only the Firebase features as you need -->
    <script src="/__/firebase/7.21.0/firebase-auth.js"></script>
    <script src="/__/firebase/7.21.0/firebase-firestore.js"></script>
    <script src="/__/firebase/7.21.0/firebase-functions.js"></script>

    <!-- Initialize Firebase -->
    <script src="/__/firebase/init.js"></script>

推荐答案

我发现,SDK版本7.21.1破坏了来自javascript Web客户端的可调用函数.如果您降级到7.21.0,它应该可以正常工作.最新的7.22.0似乎还是坏了.

I have found that callable functions from javascript web clients are broken with SDK version 7.21.1. If you downgrade to 7.21.0, it should work OK. The latest 7.22.0 still seems broken.

如果您要跟踪,则此文件已提交到GitHub 它.

This has been filed on GitHub if you want to track it.

更新2020年10月5日:显然,此问题已在7.22.1中修复.

Update Oct 5, 2020: Apparently this has been fixed in 7.22.1.

这篇关于Firebase函数无法在应用程序中使用调用函数,返回内部错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆