Firebase Functions throw function with internal error [closed]

橙三吉。 提交于 2021-02-11 12:22:37

问题


I am developing a project under Firebase Hosting with Firebase Functions. Index.js:

exports.simpleFunction = functions.https.onCall((data, context) => {
    return data;
});

Index.html:

var simpleFunction = firebase.functions().httpsCallable('simpleFunction');
    
simpleFunction("12").then (function(result) {
                                    console.log(result);
                                }).catch(function(error) {
                                    console.log("Error code:" + error.code);
                                });

In console I only get:

"Error code: Internal"

Could anybody help me figure out what happens?


回答1:


I reproduced your scenario on my project and your code works as expected, this is my HTML file

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Welcome to Firebase Hosting</title>
    <script  src="/__/firebase/8.0.0/firebase.js"></script>
    <script  src="/__/firebase/8.0.0/firebase-app.js"></script>
    <script  src="/__/firebase/8.0.0/firebase-functions.js"></script>
    <script  src="/__/firebase/init.js"></script>

    <style media="screen">

    </style>
</head>
<body>

Hello world!!


</body>

<script>html
    let simpleFunction = firebase.functions().httpsCallable('simpleFunction');

    simpleFunction("12").then(function (result) {
        console.log(result);
    }).catch(function (error) {
        console.log("Error code:" + error.code);
    });
</script>
</html>

I'm using latest firebase web packages and my function supports unauthenticated access.

Update I was able to reproduce this issue

I tried to invoke another function (python function) but since firebase-functions package doesn't exists on python, this looks the root cause, try to update your firebase-functions package or try with my reproduction example.

package.json

{
  "name": "sample-http",
  "version": "0.0.1",
  "dependencies": {
    "firebase-admin": "~9.2.0",
    "firebase-functions": "^3.11.0"  
  }
}

function

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


exports.simpleFunction = functions.https.onCall((data, context) => {
    return data;
});


来源:https://stackoverflow.com/questions/64560828/firebase-functions-throw-function-with-internal-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!