Firebase函数抛出具有内部错误的函数 [英] Firebase Functions throw function with internal error
问题描述
我正在使用Firebase功能在Firebase托管下开发一个项目.Index.js:
I am developing a project under Firebase Hosting with Firebase Functions. Index.js:
exports.simpleFunction = functions.https.onCall((data, context) => {
return data;
});
Index.html:
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:
错误代码:内部"
有人可以帮我弄清楚会发生什么吗?
Could anybody help me figure out what happens?
推荐答案
我在项目中复制了您的方案,您的代码按预期工作,这是我的HTML文件
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>
我正在使用最新的Firebase Web软件包,并且我的函数支持未经身份验证的访问权限.
I'm using latest firebase web packages and my function supports unauthenticated access.
更新,我能够重现此问题
我试图调用另一个函数(python函数),但是由于firebase-functions软件包在python上不存在,这似乎是根本原因,请尝试更新您的firebase-functions软件包或尝试使用我的复制示例.
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"
}
}
功能
const functions = require('firebase-functions');
exports.simpleFunction = functions.https.onCall((data, context) => {
return data;
});
这篇关于Firebase函数抛出具有内部错误的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!