Firebase实时数据库的函数错误

15

我是一个新手,正在尝试使用Firebase函数与实时数据库(模拟器套件)一起使用。但是当我尝试使用Firebase函数设置数据库中的值时,它会出现错误并且无法将该值设置到数据库中。

错误:

17:33:14
I
function[us-central1-textToLength]
[2021-11-05T12:03:14.194Z]  @firebase/database: FIREBASE WARNING: wss:// URL used, but browser isn't known to support websockets.  Trying anyway. 
17:34:18
I
function[us-central1-textToLength]
[2021-11-05T12:04:18.762Z]  @firebase/database: FIREBASE WARNING: wss:// URL used, but browser isn't known to support websockets.  Trying anyway. 
17:35:06
I
function[us-central1-textToLength]
[2021-11-05T12:05:06.473Z]  @firebase/database: FIREBASE WARNING: wss:// URL used, but browser isn't known to support websockets.  Trying anyway. 
17:35:54
I
function[us-central1-textToLength]
[2021-11-05T12:05:54.409Z]  @firebase/database: FIREBASE WARNING: wss:// URL used, but browser isn't known to support websockets.  Trying anyway. 

Firebase函数代码:

const functions = require('firebase-functions');
var admin = require("firebase-admin");
admin.initializeApp(); 

var database = admin.database();

exports.helloWorld = functions.https.onRequest((request, response) => {
    response.send("Hello from Firebase!");
});

exports.textToLength = functions.https.onRequest((request, response) => {
    var tex = request.query.text;
    var textLength = tex.length;
    console.log(textLength);
    database.ref().child('test').set("op");
    response.send(String(textLength));
});

依赖项:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "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": "14"
  },
  "main": "index.js",
  "dependencies": {
    "firebase-admin": "^9.8.0",
    "firebase-functions": "^3.14.1",
    "@firebase/database-compat": "0.1.2" 
  },
  "devDependencies": {
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}

已安装的npm软件包

+-- @firebase/app-compat@0.1.7
| +-- @firebase/app@0.7.6
| | +-- @firebase/component@0.5.8
| | | +-- @firebase/util@1.4.1 deduped
| | | `-- tslib@2.3.1 deduped
| | +-- @firebase/logger@0.3.1
| | | `-- tslib@2.3.1 deduped
| | +-- @firebase/util@1.4.1
| | | `-- tslib@2.3.1 deduped
| | `-- tslib@2.3.1 deduped
| +-- @firebase/component@0.5.8
| | +-- @firebase/util@1.4.1 deduped
| | `-- tslib@2.3.1 deduped
| +-- @firebase/logger@0.3.1
| | `-- tslib@2.3.1 deduped
| +-- @firebase/util@1.4.1
| | `-- tslib@2.3.1 deduped
| `-- tslib@2.3.1
+-- @firebase/database-compat@0.1.2
| +-- @firebase/component@0.5.7
| | +-- @firebase/util@1.4.0 deduped
| | `-- tslib@2.3.1 deduped
| +-- @firebase/database@0.12.2
| | +-- @firebase/auth-interop-types@0.1.6
| | +-- @firebase/component@0.5.7 deduped
| | +-- @firebase/logger@0.3.0 deduped
| | +-- @firebase/util@1.4.0 deduped
| | +-- faye-websocket@0.11.4
| | | `-- websocket-driver@0.7.4
| | |   +-- http-parser-js@0.5.3
| | |   +-- safe-buffer@5.2.1 deduped
| | |   `-- websocket-extensions@0.1.4
| | `-- tslib@2.3.1 deduped
| +-- @firebase/database-types@0.9.1
| | +-- @firebase/app-types@0.7.0
| | `-- @firebase/util@1.4.0 deduped
| +-- @firebase/logger@0.3.0
| | `-- tslib@2.3.1 deduped
| +-- @firebase/util@1.4.0
| | `-- tslib@2.3.1 deduped
| `-- tslib@2.3.1 deduped
`-- firebase-admin@10.0.0
  +-- @firebase/database-compat@0.1.2 deduped
  +-- @firebase/database-types@0.7.3
  | `-- @firebase/app-types@0.6.3
  +-- @google-cloud/firestore@4.15.1
  | +-- fast-deep-equal@3.1.3
  | +-- functional-red-black-tree@1.0.1
  | +-- google-gax@2.28.0

2
今天遇到了同样的问题.. 昨天还好好的。 - Athif Shaffy
1
Frank Puffelen,请帮助我们的团队。我遇到了Socket错误的生产问题,但无论如何都解决不了。 - Neilor Caldeira
1
在本地机器(Mac/M1)上尝试测试 Google Cloud 函数时,我也遇到了同样的问题。 - Stephane B.
完全相同的问题 - blu potatos
5个回答

10

同时,如果您使用的是最新版本的 Admin SDK,可以将 @firebase/database-compat 固定到版本 0.1.2,在您的 package.json 文件中作为临时修复措施。

"dependencies": { "@firebase/database-compat": "0.1.2" }

这对我很有效。

参考:https://github.com/firebase/firebase-admin-node/issues/1487


我再次收到了相同的错误/警告,请问您能否检查一下我的package.json文件是否正确? - Ayush Yadav
你能分享一下你的 package.json 文件吗? - Kasirajan M
我尝试了,对我没用。 - blu potatos

5
同时,如果你使用最新的Admin SDK版本,你可以在你的package.json文件中将@firebase/database-compat固定到0.1.2版本作为临时解决方案。
"dependencies": { "@firebase/database-compat": "0.1.2" }
这对我有用。
参考:https://github.com/firebase/firebase-admin-node/issues/1487 我参考了这个例子,它起作用了,但是为了使其工作,需要通过删除node_modules文件夹和package_lock.json文件并运行npm install --package-lock-only来重新构建你的package-lock.json文件。

我尝试过了,但是还是不行。我删除了node_module文件夹和package_lock.json文件。然后在我的function文件夹中运行了命令npm install --package-lock-only。接着我在我的package.json依赖项中添加了"@firebase/database-compat": "0.1.2"。当我服务或部署网站时,我一直遇到相同的错误"FIREBASE WARNING: wss:// URL used, but browser isn't known to support websockets."。对于Firestore来说,完全相同的代码却可以正常工作。有没有什么建议来修复这个bug? - blu potatos
从 Github 的问题中,我了解到这个问题是由于新的 @firebase/database 包发布导致的,降级到较低版本几乎可以解决所有开发者的问题。所以我认为你正在做错某些事情。 - Ayush Yadav
是的,现在它可以工作了。我看到他们正式修复了这个漏洞。 - blu potatos

2

我尝试使用那个修复程序,但它仍然给我相同的警告。您可以检查上面附加的 package.json 代码,在那里我使用了相同的版本。 - Ayush Yadav

0

这个问题似乎是由最近发布的@firebase/*包之一引起的。我还不知道哪个版本有问题,但是通过将我的yarn.lock文件恢复到最近的更改,我成功解决了这个问题。

以下是我当前的@firebase依赖版本,我不再遇到这个问题:

"@firebase/analytics-types@0.4.0":
  version "0.4.0"
  resolved "https://registry.yarnpkg.com/@firebase/analytics-types/-/analytics-types-0.4.0.tgz#d6716f9fa36a6e340bc0ecfe68af325aa6f60508"
  integrity sha512-Jj2xW+8+8XPfWGkv9HPv/uR+Qrmq37NPYT352wf7MvE9LrstpLVmFg3LqG6MCRr5miLAom5sen2gZ+iOhVDeRA==

"@firebase/analytics@0.6.4":
  version "0.6.4"
  resolved "https://registry.yarnpkg.com/@firebase/analytics/-/analytics-0.6.4.tgz#1e0c446e0045c94077f2d06ff3ba33e86d860398"
  integrity sha512-Lhnk5pXeDKoPf1b2cggWQaqCtNq+jn6IkhHMIo+7VztVt3i8ovnGuhAn/0hLC+XxvVWJ9q6CXIoGStkwvecDoA==
  dependencies:
    "@firebase/analytics-types" "0.4.0"
    "@firebase/component" "0.2.0"
    "@firebase/installations" "0.4.20"
    "@firebase/logger" "0.2.6"
    "@firebase/util" "0.3.4"
    tslib "^1.11.1"

"@firebase/analytics@0.6.5":
  version "0.6.5"
  resolved "https://registry.yarnpkg.com/@firebase/analytics/-/analytics-0.6.5.tgz#9f28575ba13e7f04cf1ae506322f11fb80bcb611"
  integrity sha512-0yNdAtLRIS7wTs8eUSPHfQyypAbGha0MVpfnl18CTq1sLpdzHICn7CyCMYhc0ewlFdTCIHLjw4ZQoSTwtBHfkQ==
  dependencies:
    "@firebase/analytics-types" "0.4.0"
    "@firebase/component" "0.2.1"
    "@firebase/installations" "0.4.21"
    "@firebase/logger" "0.2.6"
    "@firebase/util" "0.4.0"
    tslib "^2.0.0"

"@firebase/app-types@0.6.1":
  version "0.6.1"
  resolved "https://registry.yarnpkg.com/@firebase/app-types/-/app-types-0.6.1.tgz#dcbd23030a71c0c74fc95d4a3f75ba81653850e9"
  integrity sha512-L/ZnJRAq7F++utfuoTKX4CLBG5YR7tFO3PLzG1/oXXKEezJ0kRL3CMRoueBEmTCzVb/6SIs2Qlaw++uDgi5Xyg==

"@firebase/app-types@0.6.3":
  version "0.6.3"
  resolved "https://registry.yarnpkg.com/@firebase/app-types/-/app-types-0.6.3.tgz#3f10514786aad846d74cd63cb693556309918f4b"
  integrity sha512-/M13DPPati7FQHEQ9Minjk1HGLm/4K4gs9bR4rzLCWJg64yGtVC0zNg9gDpkw9yc2cvol/mNFxqTtd4geGrwdw==

"@firebase/app-types@0.7.0":
  version "0.7.0"
  resolved "https://registry.yarnpkg.com/@firebase/app-types/-/app-types-0.7.0.tgz#c9e16d1b8bed1a991840b8d2a725fb58d0b5899f"
  integrity sha512-6fbHQwDv2jp/v6bXhBw2eSRbNBpxHcd1NBF864UksSMVIqIyri9qpJB1Mn6sGZE+bnDsSQBC5j2TbMxYsJQkQg==

"@firebase/app@0.6.15":
  version "0.6.15"
  resolved "https://registry.yarnpkg.com/@firebase/app/-/app-0.6.15.tgz#a426f02eb7210d1ecc77d49296bbb1ec8481a791"
  integrity sha512-VfULP09cci4xk+iAU6CB2CUNU/vbpAOoUleDdspXFphV9Yw36anb8RjaHGcN1DRR7LNb7vznNJXHk8FJhC8VWQ==
  dependencies:
    "@firebase/app-types" "0.6.1"
    "@firebase/component" "0.2.0"
    "@firebase/logger" "0.2.6"
    "@firebase/util" "0.3.4"
    dom-storage "2.1.0"
    tslib "^1.11.1"
    xmlhttprequest "1.8.0"

"@firebase/app@0.6.16":
  version "0.6.16"
  resolved "https://registry.yarnpkg.com/@firebase/app/-/app-0.6.16.tgz#d87f3d70e59dd44e8f14fd45a575b8ffe58be406"
  integrity sha512-QGqfvDQ4AK54y2ysttdgtTsyuLGfN0OksdmWSHLDs7HBJg9nJkZUuFA/cJ1cftpPSVxpCbnro+OU1FtRgapzAA==
  dependencies:
    "@firebase/app-types" "0.6.1"
    "@firebase/component" "0.2.1"
    "@firebase/logger" "0.2.6"
    "@firebase/util" "0.4.0"
    dom-storage "2.1.0"
    tslib "^2.0.0"
    xmlhttprequest "1.8.0"

"@firebase/auth-interop-types@0.1.5":
  version "0.1.5"
  resolved "https://registry.yarnpkg.com/@firebase/auth-interop-types/-/auth-interop-types-0.1.5.tgz#9fc9bd7c879f16b8d1bb08373a0f48c3a8b74557"
  integrity sha512-88h74TMQ6wXChPA6h9Q3E1Jg6TkTHep2+k63OWg3s0ozyGVMeY+TTOti7PFPzq5RhszQPQOoCi59es4MaRvgCw==

"@firebase/auth-interop-types@0.1.6":
  version "0.1.6"
  resolved "https://registry.yarnpkg.com/@firebase/auth-interop-types/-/auth-interop-types-0.1.6.tgz#5ce13fc1c527ad36f1bb1322c4492680a6cf4964"
  integrity sha512-etIi92fW3CctsmR9e3sYM3Uqnoq861M0Id9mdOPF6PWIg38BXL5k4upCNBggGUpLIS0H1grMOvy/wn1xymwe2g==

"@firebase/auth-types@0.10.2":
  version "0.10.2"
  resolved "https://registry.yarnpkg.com/@firebase/auth-types/-/auth-types-0.10.2.tgz#3fad953380c447b7545122430a4c7a9bc8355001"
  integrity sha512-0GMWVWh5TBCYIQfVerxzDsuvhoFpK0++O9LtP3FWkwYo7EAxp6w0cftAg/8ntU1E5Wg56Ry0b6ti/YGP6g0jlg==

"@firebase/auth@0.16.4":
  version "0.16.4"
  resolved "https://registry.yarnpkg.com/@firebase/auth/-/auth-0.16.4.tgz#6249d80f1e974b0db122930ae9fac885eccead5c"
  integrity sha512-zgHPK6/uL6+nAyG9zqammHTF1MQpAN7z/jVRLYkDZS4l81H08b2SzApLbRfW/fmy665xqb5MK7sVH0V1wsiCNw==
  dependencies:
    "@firebase/auth-types" "0.10.2"

"@firebase/component@0.2.0":
  version "0.2.0"
  resolved "https://registry.yarnpkg.com/@firebase/component/-/component-0.2.0.tgz#9d48327b3377b84ef22266ec6ab13416ea174c0a"
  integrity sha512-QJJxMEzLRMWjujPBrrS32BScg1wmdY/dZWR8nAEzyC8WKQsNevYR9ZKLbBYxaN0umH9yf5C40kwmy+gI8jStPw==
  dependencies:
    "@firebase/util" "0.3.4"
    tslib "^1.11.1"

"@firebase/component@0.2.1":
  version "0.2.1"
  resolved "https://registry.yarnpkg.com/@firebase/component/-/component-0.2.1.tgz#998e2909f87993a2ad7ea718dbf109cd8f5c7ca3"
  integrity sha512-WfBFABfKYcRFjgMA7ydPLokSa+GkuZd+FD00KrZLAfslpHxs6cCFXdklvP8NEb1oDLqYakRXBqWdelH9/Whacg==
  dependencies:
    "@firebase/util" "0.4.0"
    tslib "^2.0.0"

"@firebase/component@0.5.7":
  version "0.5.7"
  resolved "https://registry.yarnpkg.com/@firebase/component/-/component-0.5.7.tgz#a50c5fbd14a2136a99ade6f59f53498729c0f174"
  integrity sha512-CiAHUPXh2hn/lpzMShNmfAxHNQhKQwmQUJSYMPCjf2bCCt4Z2vLGpS+UWEuNFm9Zf8LNmkS+Z+U/s4Obi5carg==
  dependencies:
    "@firebase/util" "1.4.0"
    tslib "^2.1.0"

"@firebase/database-compat@^0.1.1":
  version "0.1.1"
  resolved "https://registry.yarnpkg.com/@firebase/database-compat/-/database-compat-0.1.1.tgz#9fe69e3bd3f71d29011bb6ca793f38edb65ca536"
  integrity sha512-K3DFWiw0YkLZtlfA9TOGPw6zVXKu5dQ1XqIGztUufFVRYW8IizReXVxzSSmJNR4Adr2LiU9j66Wenc6e5UfwaQ==
  dependencies:
    "@firebase/component" "0.5.7"
    "@firebase/database" "0.12.1"
    "@firebase/database-types" "0.9.1"
    "@firebase/logger" "0.3.0"
    "@firebase/util" "1.4.0"
    tslib "^2.1.0"

"@firebase/database-types@0.7.0":
  version "0.7.0"
  resolved "https://registry.yarnpkg.com/@firebase/database-types/-/database-types-0.7.0.tgz#ab140d178ded676e60d8ade8c8f13de8e01e7e1e"
  integrity sha512-FduQmPpUUOHgbOt7/vWlC1ntSLMEqqYessdQ/ODd7RFWm53iVa0T1mpIDtNwqd8gW3k7cajjSjcLjfQGtvLGDg==
  dependencies:
    "@firebase/app-types" "0.6.1"

"@firebase/database-types@0.9.1":
  version "0.9.1"
  resolved "https://registry.yarnpkg.com/@firebase/database-types/-/database-types-0.9.1.tgz#0cab989e8154d812b535d80f23c1578b1d391f5f"
  integrity sha512-RUixK/YrbpxbfdE+nYP0wMcEsz1xPTnafP0q3UlSS/+fW744OITKtR1J0cMRaXbvY7EH0wUVTNVkrtgxYY8IgQ==
  dependencies:
    "@firebase/app-types" "0.7.0"
    "@firebase/util" "1.4.0"

"@firebase/database-types@^0.7.2":
  version "0.7.3"
  resolved "https://registry.yarnpkg.com/@firebase/database-types/-/database-types-0.7.3.tgz#819f16dd4c767c864b460004458620f265a3f735"
  integrity sha512-dSOJmhKQ0nL8O4EQMRNGpSExWCXeHtH57gGg0BfNAdWcKhC8/4Y+qfKLfWXzyHvrSecpLmO0SmAi/iK2D5fp5A==
  dependencies:
    "@firebase/app-types" "0.6.3"

"@firebase/database@0.12.1":
  version "0.12.1"
  resolved "https://registry.yarnpkg.com/@firebase/database/-/database-0.12.1.tgz#7e43f27ac4057858d5bd0dd371b134b304fecdb0"
  integrity sha512-Ethk0hc476qnkSKNBa+8Yc7iM8AO69HYWsaD+QUC983FZtnuMyNLHtEeSUbLQYvyHo7cOjcc52slop14WmfZeQ==
  dependencies:
    "@firebase/auth-interop-types" "0.1.6"
    "@firebase/component" "0.5.7"
    "@firebase/logger" "0.3.0"
    "@firebase/util" "1.4.0"
    faye-websocket "0.11.4"
    tslib "^2.1.0"

"@firebase/database@0.9.4":
  version "0.9.4"
  resolved "https://registry.yarnpkg.com/@firebase/database/-/database-0.9.4.tgz#7f108ad96f099beae78c06a86f81edf4302fd4c4"
  integrity sha512-Fw2bA4OyxAMqLy8xtoZKlUAuDWjjH/z4AInRTAzHxgegXDbu0UK+VM0pmY44RuM2cmnVY4aW6xLXAdDKTY1aJQ==
  dependencies:
    "@firebase/auth-interop-types" "0.1.5"
    "@firebase/component" "0.2.0"
    "@firebase/database-types" "0.7.0"
    "@firebase/logger" "0.2.6"
    "@firebase/util" "0.3.4"
    faye-websocket "0.11.3"
    tslib "^1.11.1"

"@firebase/database@0.9.5":
  version "0.9.5"
  resolved "https://registry.yarnpkg.com/@firebase/database/-/database-0.9.5.tgz#3f4f1dac759d138cf7cfaef5121640cba506f700"
  integrity sha512-sfS5ZvU7UqztMAP9y3t/AQRNhqDrHJT6/W1JBmEivjSxf1MLLbCafZMFbksuvl2iog73wOGDuoDzSHvhtSQvvg==
  dependencies:
    "@firebase/auth-interop-types" "0.1.5"
    "@firebase/component" "0.2.1"
    "@firebase/database-types" "0.7.0"
    "@firebase/logger" "0.2.6"
    "@firebase/util" "0.4.0"
    faye-websocket "0.11.3"
    tslib "^2.0.0"

"@firebase/firestore-types@2.1.0":
  version "2.1.0"
  resolved "https://registry.yarnpkg.com/@firebase/firestore-types/-/firestore-types-2.1.0.tgz#ad406c6fd7f0eae7ea52979f712daa0166aef665"
  integrity sha512-jietErBWihMvJkqqEquQy5GgoEwzHnMXXC/TsVoe9FPysXm1/AeJS12taS7ZYvenAtyvL/AEJyKrRKRh4adcJQ==

"@firebase/firestore-types@2.2.0":
  version "2.2.0"
  resolved "https://registry.yarnpkg.com/@firebase/firestore-types/-/firestore-types-2.2.0.tgz#9a3f3f2906232c3b4a726d988a6ef077f35f9093"
  integrity sha512-5kZZtQ32FIRJP1029dw+ZVNRCclKOErHv1+Xn0pw/5Fq3dxroA/ZyFHqDu+uV52AyWHhNLjCqX43ibm4YqOzRw==

"@firebase/firestore@2.1.7":
  version "2.1.7"
  resolved "https://registry.yarnpkg.com/@firebase/firestore/-/firestore-2.1.7.tgz#039d1d469bd14d89a2d091ec7887a92cc7ab11a7"
  integrity sha512-sh+aX6udS8a+rwmlJO4zJwvoMC1D2x1CiPvj0nFYWhILRKWvztk/bOA3lT2FWcHY4kr/7x+CnqfwtiOSaufdNQ==
  dependencies:
    "@firebase/component" "0.2.0"
    "@firebase/firestore-types" "2.1.0"
    "@firebase/logger" "0.2.6"
    "@firebase/util" "0.3.4"
    "@firebase/webchannel-wrapper" "0.4.1"
    "@grpc/grpc-js" "^1.0.0"
    "@grpc/proto-loader" "^0.5.0"
    node-fetch "2.6.1"
    tslib "^1.11.1"

"@firebase/firestore@2.2.0":
  version "2.2.0"
  resolved "https://registry.yarnpkg.com/@firebase/firestore/-/firestore-2.2.0.tgz#b7cf2d6a65b432bec43430f1d9f696c07b881e90"
  integrity sha512-/p0oR73zgAlEHgqCIt5v2m8ADOign6APkZ0QG5bJQVSDqPXjB89ktI3v8x0qtRtzKm/pd3lmyoD/raOh/ItsZA==
  dependencies:
    "@firebase/component" "0.2.1"
    "@firebase/firestore-types" "2.2.0"
    "@firebase/logger" "0.2.6"
    "@firebase/util" "0.4.0"
    "@firebase/webchannel-wrapper" "0.4.1"
    "@grpc/grpc-js" "^1.0.0"
    "@grpc/proto-loader" "^0.5.0"
    node-fetch "2.6.1"
    tslib "^2.0.0"

"@firebase/functions-types@0.4.0":
  version "0.4.0"
  resolved "https://registry.yarnpkg.com/@firebase/functions-types/-/functions-types-0.4.0.tgz#0b789f4fe9a9c0b987606c4da10139345b40f6b9"
  integrity sha512-3KElyO3887HNxtxNF1ytGFrNmqD+hheqjwmT3sI09FaDCuaxGbOnsXAXH2eQ049XRXw9YQpHMgYws/aUNgXVyQ==

"@firebase/functions@0.6.2":
  version "0.6.2"
  resolved "https://registry.yarnpkg.com/@firebase/functions/-/functions-0.6.2.tgz#5ed6822248c14a4287ec156afc980d76d57e470a"
  integrity sha512-f+NxRd0k5RBPZUPj8lykeNMku8TpJTgZaRd3T6cXb8HbmSg/VY7uxQSGOXe11X2gSv/TvcwTQttViFzRMDs7CQ==
  dependencies:
    "@firebase/component" "0.2.0"
    "@firebase/functions-types" "0.4.0"
    "@firebase/messaging-types" "0.5.0"
    node-fetch "2.6.1"
    tslib "^1.11.1"

"@firebase/functions@0.6.3":
  version "0.6.3"
  resolved "https://registry.yarnpkg.com/@firebase/functions/-/functions-0.6.3.tgz#015e1efd1cf6749dddbdc056215d3035b43d000c"
  integrity sha512-02dqjin4V9PvuZLU6d14azyRZZ5cUSPT5CvE2SbGjAcXYdlFIg5Cy6T50dl48UsbmmNO40kXNB1dGESp2A4cWw==
  dependencies:
    "@firebase/component" "0.2.1"
    "@firebase/functions-types" "0.4.0"
    "@firebase/messaging-types" "0.5.0"
    node-fetch "2.6.1"
    tslib "^2.0.0"

"@firebase/installations-types@0.3.4":
  version "0.3.4"
  resolved "https://registry.yarnpkg.com/@firebase/installations-types/-/installations-types-0.3.4.tgz#589a941d713f4f64bf9f4feb7f463505bab1afa2"
  integrity sha512-RfePJFovmdIXb6rYwtngyxuEcWnOrzdZd9m7xAW0gRxDIjBT20n3BOhjpmgRWXo/DAxRmS7bRjWAyTHY9cqN7Q==

"@firebase/installations@0.4.20":
  version "0.4.20"
  resolved "https://registry.yarnpkg.com/@firebase/installations/-/installations-0.4.20.tgz#e52a5904c41ac0be0bb2ab1e320b8e1018ed2630"
  integrity sha512-ddUPZQKHWJzqg3g11hxHIPhp3oMEmsPo0GSxtp9Xd2VLRU64MFNAAt5PiBbq1K92ukZVoNh6Ki6J6+hJEQcGQw==
  dependencies:
    "@firebase/component" "0.2.0"
    "@firebase/installations-types" "0.3.4"
    "@firebase/util" "0.3.4"
    idb "3.0.2"
    tslib "^1.11.1"

"@firebase/installations@0.4.21":
  version "0.4.21"
  resolved "https://registry.yarnpkg.com/@firebase/installations/-/installations-0.4.21.tgz#152fae36647eb08c1e94f94ca160d3273a401117"
  integrity sha512-tMoAb1lHAQefdknWbKxSp2CEWWV/f4aeq4PjhzWurJEJN4RQ620ITbtuKregnGnYHu9lDzhyZ51H4s6+BhjCxA==
  dependencies:
    "@firebase/component" "0.2.1"
    "@firebase/installations-types" "0.3.4"
    "@firebase/util" "0.4.0"
    idb "3.0.2"
    tslib "^2.0.0"

"@firebase/logger@0.2.6":
  version "0.2.6"
  resolved "https://registry.yarnpkg.com/@firebase/logger/-/logger-0.2.6.tgz#3aa2ca4fe10327cabf7808bd3994e88db26d7989"
  integrity sha512-KIxcUvW/cRGWlzK9Vd2KB864HlUnCfdTH0taHE0sXW5Xl7+W68suaeau1oKNEqmc3l45azkd4NzXTCWZRZdXrw==

"@firebase/logger@0.3.0":
  version "0.3.0"
  resolved "https://registry.yarnpkg.com/@firebase/logger/-/logger-0.3.0.tgz#a3992e40f62c10276dbfcb8b4ab376b7e25d7fd9"
  integrity sha512-7oQ+TctqekfgZImWkKuda50JZfkmAKMgh5qY4aR4pwRyqZXuJXN1H/BKkHvN1y0S4XWtF0f/wiCLKHhyi1ppPA==
  dependencies:
    tslib "^2.1.0"

"@firebase/messaging-types@0.5.0":
  version "0.5.0"
  resolved "https://registry.yarnpkg.com/@firebase/messaging-types/-/messaging-types-0.5.0.tgz#c5d0ef309ced1758fda93ef3ac70a786de2e73c4"
  integrity sha512-QaaBswrU6umJYb/ZYvjR5JDSslCGOH6D9P136PhabFAHLTR4TWjsaACvbBXuvwrfCXu10DtcjMxqfhdNIB1Xfg==

"@firebase/messaging@0.7.4":
  version "0.7.4"
  resolved "https://registry.yarnpkg.com/@firebase/messaging/-/messaging-0.7.4.tgz#d527506de7690731f0a83e6a82a6aa590b14523a"
  integrity sha512-xIZ1vHnOcHAaj+H/gS8tu3QolR9up+fyTfgVLEFbZRsbAiLuIvuaoJwTHLAUTs/nJF6GtEGscRD4Jx/aFmEJRw==
  dependencies:
    "@firebase/component" "0.2.0"
    "@firebase/installations" "0.4.20"
    "@firebase/messaging-types" "0.5.0"
    "@firebase/util" "0.3.4"
    idb "3.0.2"
    tslib "^1.11.1"

"@firebase/messaging@0.7.5":
  version "0.7.5"
  resolved "https://registry.yarnpkg.com/@firebase/messaging/-/messaging-0.7.5.tgz#1efe40b1785535ee13af323b7f2deb7cceb2a94a"
  integrity sha512-jA1pdV/DrfvzSVKLuff2hYo2AvU0CdZ901TngxscJqKYViZEoqAGw2v/kC70uRwEG0Tc2M/SRHstHpeFADlP0Q==
  dependencies:
    "@firebase/component" "0.2.1"
    "@firebase/installations" "0.4.21"
    "@firebase/messaging-types" "0.5.0"
    "@firebase/util" "0.4.0"
    idb "3.0.2"
    tslib "^2.0.0"

"@firebase/performance-types@0.0.13":
  version "0.0.13"
  resolved "https://registry.yarnpkg.com/@firebase/performance-types/-/performance-types-0.0.13.tgz#58ce5453f57e34b18186f74ef11550dfc558ede6"
  integrity sha512-6fZfIGjQpwo9S5OzMpPyqgYAUZcFzZxHFqOyNtorDIgNXq33nlldTL/vtaUZA8iT9TT5cJlCrF/jthKU7X21EA==

"@firebase/performance@0.4.6":
  version "0.4.6"
  resolved "https://registry.yarnpkg.com/@firebase/performance/-/performance-0.4.6.tgz#e6b8b4c7c21e657af3a8e87c422cd4d199b57fa1"
  integrity sha512-fy9YPYnvePFxme7euyi8B658gF8JUQhAB1qv6hVw+HqjVZQIANhwM9AUBi9+5jikD7gD1CnU7EjREvoy8MJiAw==
  dependencies:
    "@firebase/component" "0.2.0"
    "@firebase/installations" "0.4.20"
    "@firebase/logger" "0.2.6"
    "@firebase/performance-types" "0.0.13"
    "@firebase/util" "0.3.4"
    tslib "^1.11.1"

"@firebase/performance@0.4.7":
  version "0.4.7"
  resolved "https://registry.yarnpkg.com/@firebase/performance/-/performance-0.4.7.tgz#be201b76667f59aabd31e7fb73977ed5b172d0c3"
  integrity sha512-wxau4qrAy5W+kIoXPUm5hJVX4+vY3wVC9QqWNzoqb+L5tMHxIoeEqxvJo8abjv4pa0/YaVl1XKAZdvvoe7c/dA==
  dependencies:
    "@firebase/component" "0.2.1"
    "@firebase/installations" "0.4.21"
    "@firebase/logger" "0.2.6"
    "@firebase/performance-types" "0.0.13"
    "@firebase/util" "0.4.0"
    tslib "^2.0.0"

"@firebase/polyfill@0.3.36":
  version "0.3.36"
  resolved "https://registry.yarnpkg.com/@firebase/polyfill/-/polyfill-0.3.36.tgz#c057cce6748170f36966b555749472b25efdb145"
  integrity sha512-zMM9oSJgY6cT2jx3Ce9LYqb0eIpDE52meIzd/oe/y70F+v9u1LDqk5kUF5mf16zovGBWMNFmgzlsh6Wj0OsFtg==
  dependencies:
    core-js "3.6.5"
    promise-polyfill "8.1.3"
    whatwg-fetch "2.0.4"

"@firebase/remote-config-types@0.1.9":
  version "0.1.9"
  resolved "https://registry.yarnpkg.com/@firebase/remote-config-types/-/remote-config-types-0.1.9.tgz#fe6bbe4d08f3b6e92fce30e4b7a9f4d6a96d6965"
  integrity sha512-G96qnF3RYGbZsTRut7NBX0sxyczxt1uyCgXQuH/eAfUCngxjEGcZQnBdy6mvSdqdJh5mC31rWPO4v9/s7HwtzA==

"@firebase/remote-config@0.1.31":
  version "0.1.31"
  resolved "https://registry.yarnpkg.com/@firebase/remote-config/-/remote-config-0.1.31.tgz#092cefc946558a1924d34960163f19b1adf8253d"
  integrity sha512-QWjDsrLSqQnq/YTb3TSOJtIv7z2GXB7mTiwXE43NxYmsOX2z8KBlBBEHf9TcWk+90MKUTFfurDgYJN4rlIOxPg==
  dependencies:
    "@firebase/component" "0.2.0"
    "@firebase/installations" "0.4.20"
    "@firebase/logger" "0.2.6"
    "@firebase/remote-config-types" "0.1.9"
    "@firebase/util" "0.3.4"
    tslib "^1.11.1"

"@firebase/remote-config@0.1.32":
  version "0.1.32"
  resolved "https://registry.yarnpkg.com/@firebase/remote-config/-/remote-config-0.1.32.tgz#a3ffac5039b6a785d83bf5864b58b06fe0b8cfea"
  integrity sha512-nPPhKSUHgwlv2hazke6keBkkadW+/VCpNbq3P9L8oWxq7hKQz7MYAC5LU6PqexNmWQqGFiYyX5J8XDUU3gH/NQ==
  dependencies:
    "@firebase/component" "0.2.1"
    "@firebase/installations" "0.4.21"
    "@firebase/logger" "0.2.6"
    "@firebase/remote-config-types" "0.1.9"
    "@firebase/util" "0.4.0"
    tslib "^2.0.0"

"@firebase/rules-unit-testing@1.2.4":
  version "1.2.4"
  resolved "https://registry.yarnpkg.com/@firebase/rules-unit-testing/-/rules-unit-testing-1.2.4.tgz#7c378f7f0e277cf84016946b6d6af269a439e25a"
  integrity sha512-suYV3B3UaZS/+4x+94gAaAZTaYn7r3du5h4lYunvY4LAzimtv8sVFhxNvlfV3awDCJUoAMlh6MFAm7wg2rXJ4g==
  dependencies:
    "@firebase/logger" "0.2.6"
    "@firebase/util" "0.4.0"
    firebase "8.3.0"
    request "2.88.2"

"@firebase/storage-types@0.3.13":
  version "0.3.13"
  resolved "https://registry.yarnpkg.com/@firebase/storage-types/-/storage-types-0.3.13.tgz#cd43e939a2ab5742e109eb639a313673a48b5458"
  integrity sha512-pL7b8d5kMNCCL0w9hF7pr16POyKkb3imOW7w0qYrhBnbyJTdVxMWZhb0HxCFyQWC0w3EiIFFmxoz8NTFZDEFog==

"@firebase/storage@0.4.3":
  version "0.4.3"
  resolved "https://registry.yarnpkg.com/@firebase/storage/-/storage-0.4.3.tgz#8800fa61131890f64448b4ab536c8ee1ba9bdcdf"
  integrity sha512-53IIt6Z3BltPBPmvxF/RGlvW8nBl4wI9GMR52CjRAIj438tPNxbpIvkLB956VVB9gfZhDcPIKxg7hNtC7hXrkA==
  dependencies:
    "@firebase/component" "0.2.0"
    "@firebase/storage-types" "0.3.13"
    "@firebase/util" "0.3.4"
    tslib "^1.11.1"

"@firebase/storage@0.4.4":
  version "0.4.4"
  resolved "https://registry.yarnpkg.com/@firebase/storage/-/storage-0.4.4.tgz#e1cca95706a1a25c551134b687be975fa4853a49"
  integrity sha512-3mH6IR04Lvk16kQQ7CMumpppNcqN6RVcqSD3jzaB8P6vbzDVRyk7Dnhd00Eigd++q5FdNRpW3h8xGvHPWDYfKQ==
  dependencies:
    "@firebase/component" "0.2.1"
    "@firebase/storage-types" "0.3.13"
    "@firebase/util" "0.4.0"
    tslib "^2.0.0"

"@firebase/util@0.3.4":
  version "0.3.4"
  resolved "https://registry.yarnpkg.com/@firebase/util/-/util-0.3.4.tgz#e389d0e0e2aac88a5235b06ba9431db999d4892b"
  integrity sha512-VwjJUE2Vgr2UMfH63ZtIX9Hd7x+6gayi6RUXaTqEYxSbf/JmehLmAEYSuxS/NckfzAXWeGnKclvnXVibDgpjQQ==
  dependencies:
    tslib "^1.11.1"

"@firebase/util@0.4.0":
  version "0.4.0"
  resolved "https://registry.yarnpkg.com/@firebase/util/-/util-0.4.0.tgz#8db3d39e0ed7b991b4da2435d7e6556cb1bd6672"
  integrity sha512-z8A+9YGM61ZXQ2KBSVwxXaELOJjG+EQ374YolqNVMvWBJzTNGZGaVP81Ggl8XD10Xinyt1Dgdo86JDV0OAnvqA==
  dependencies:
    tslib "^2.0.0"

"@firebase/util@1.4.0":
  version "1.4.0"
  resolved "https://registry.yarnpkg.com/@firebase/util/-/util-1.4.0.tgz#81e985adba44b4d1f21ec9f5af9628d505891de8"
  integrity sha512-Qn58d+DVi1nGn0bA9RV89zkz0zcbt6aUcRdyiuub/SuEvjKYstWmHcHwh1C0qmE1wPf9a3a+AuaRtduaGaRT7A==
  dependencies:
    tslib "^2.1.0"

"@firebase/webchannel-wrapper@0.4.1":
  version "0.4.1"
  resolved "https://registry.yarnpkg.com/@firebase/webchannel-wrapper/-/webchannel-wrapper-0.4.1.tgz#600f2275ff54739ad5ac0102f1467b8963cd5f71"
  integrity sha512-0yPjzuzGMkW1GkrC8yWsiN7vt1OzkMIi9HgxRmKREZl2wnNPOKo/yScTjXf/O57HM8dltqxPF6jlNLFVtc2qdw==

我正在使用npm,所以没有yarn.lock文件,但是我尝试使用旧版本,但仍然遇到相同的错误。 - Ayush Yadav

0

我不确定那个日志信息的原因,但是我看到你在函数完成所有工作之前就从函数中返回了一个响应。在部署的函数中,一旦函数返回,所有后续操作都应被视为永远不会执行如此记录。一个“非活动”的函数可能随时被终止,严重受限,并且您进行的任何网络调用(例如在RTDB中设置数据)可能永远不会被执行。

我知道你是新手,但现在养成一个好习惯:不要假设调用你的函数的人是你自己。在盲目执行某些操作之前,请检查是否存在缺少的查询参数和不良数据等问题。Admin SDK绕过了数据库的安全规则,如果你不小心,恶意用户可以造成一些损害(例如将/users/$theirUid/roles/admin更新为true的用户)。

exports.textToLength = functions.https.onRequest((request, response) => {
    const { text: queryText } = request.query;
    
    if (!queryText)
      return response.status(400).send("Missing ?text");
    if (typeof queryText !== 'string')
      return response.status(400).send("Bad value for ?text");

    const textLength = queryText.length;
    
    database.ref()
      .child('test')
      .set("op")
      .then(() => {
        console.log(`Successfully updated /test/op to ${textLength}`);
        response.send(String(textLength))
      })
      .catch((err) => {
        console.error(`Failed to update /test/op to ${textLength}: `, error);
        response.status(500).send(`Failed to update database to ${textLength}`)
      });
    ;
});

注意:在部署HTTPS请求功能时,请不要忘记处理CORS


我在 Firebase 模拟器套件中再次遇到了相同的错误。 - Ayush Yadav

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接