gpt4 book ai didi

javascript - Cloud firebase 函数错误 promise 未定义

转载 作者:行者123 更新时间:2023-11-30 19:45:26 24 4
gpt4 key购买 nike

我之前有两篇文章试图解决我的问题,并决定将所有现有代码排除在外。

我无法得到任何工作 promise 。因此,我试图复制 Doug Stevenson 的 YouTube 视频“使用 Cloud Functions 中的 HTTP 触发器学习 JavaScript Promises(第 1 部分)- Firecasts”中的示例。基于以下错误,我质疑我的环境是否是我无法获得正常工作 promise 的原因。

这些消息都没有出现在控制台日志中(根据返回的消息,我并不感到惊讶。

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const sendgrid = require('@sendgrid/mail');

admin.initializeApp();
admin.firestore().settings({
timestampsInSnapshots: true
});
exports.getMatchesNew = functions.https.onRequest((request, response) => {
console.log("In On Call", request);
admin.firestore().doc('city/seattle').get();

promise.then(snapshot => {
const data = snapshot.data();
console.log("data: ", data);
response.send(data);
})
.catch(error => {
// Handle the error
console.log(error);
response.status(400).send(error);
});
});

尝试在本地测试此功能时出现此错误使用 http://localhost:5000/wsos-base/us-central1/getMatchesNew

stack "ReferenceError: promise is not defined\n 在 exports.getMatchesNew.functions.https.onRequest (C:\WSOS-BASE\nitrofreddo-master\functions\index.js:317: 3)\n 在 cloudFunction (C:\WSOS-BASE\nitrofreddo-master\functions\node_modules\firebase-functions\lib\providers\https.js:57:9)\n 在 app.use (C:\Users\miker\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\@google-cloud\functions-emulator\src\supervisor\worker.js:151:11)\n 在 Layer.handle [as handle_request] (C:\Users\miker\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\express\lib\router\layer.js:95:5)\n 在 trim_prefix (C:\Users\miker\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\express\lib\router\index.js:317:13)\n 在 C:\Users\miker\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\express\lib\router\index.js:284:7\n 在 Function.process_params (C:\Users\miker\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\express\lib\router\index.js:335: 12)\n 在接下来 (C:\Users\miker\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\express\lib\router\index.js:275:10)\n 在 app.use (C :\Users\miker\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\@google-cloud\functions-emulator\src\supervisor\worker.js:123:7)\n 在 Layer.handle [as handle_request ] (C:\Users\miker\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\express\lib\router\layer.js:95:5)"消息“ promise 未定义”名称“ReferenceError”

我没有从以前的开发人员那里得到这方面的信息。我在设置环境时下载了最新的 Node.JS,但可能是不正确的。这是 Node.Js 版本冲突吗?还是 Firebase 版本冲突?或者???

请看我之前的帖子This shows a cloud function that is working, except for what I believe are dropped promises when trying to get user information for each mentee id

最佳答案

错误消息告诉您您从 undefined variable promise

取而代之的是:

admin.firestore().doc('city/seattle').get();

也许你的意思是这样说:

const promise = admin.firestore().doc('city/seattle').get();

关于javascript - Cloud firebase 函数错误 promise 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54987642/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com