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

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

问题描述

我被卡在了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
}

以前是节点":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>

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

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 指出,目前(2020 年 10 月)无法使用 javascript sdk 7.21.1 和 7.22.0 的 Firebase 可调用函数.

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>

推荐答案

我发现来自 javascript Web 客户端的可调用函数在 SDK 版本 7.21.1 中被破坏.如果您降级到 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 函数无法在应用程序中使用 oncall 函数,返回内部错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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