【发布时间】:2019-07-26 00:36:22
【问题描述】:
我之前有两篇文章试图解决我的问题,并决定将所有现有代码排除在外。
我无法得到任何工作承诺。因此,我尝试复制 Doug Stevenson 的 YouTube 视频“Learn JavaScript Promises (Pt.1) with HTTP Triggers in Cloud Functions - 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\i ndex.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)" 消息“未定义承诺” 名称“参考错误”
我没有从以前的开发者那里得到关于这方面的信息。我在设置环境时下载了最新的 Node.JS,但可能是不正确的。这是 Node.Js 版本冲突吗?还是 Firebase 版本冲突?还是???
【问题讨论】:
-
好吧,我没有看到
promise被定义在任何地方?向我们展示它的定义位置。
标签: javascript google-cloud-functions