Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 无法将异步函数部署到Google云函数_Node.js_Firebase_Google Cloud Functions - Fatal编程技术网

Node.js 无法将异步函数部署到Google云函数

Node.js 无法将异步函数部署到Google云函数,node.js,firebase,google-cloud-functions,Node.js,Firebase,Google Cloud Functions,我使用的是Node的最新版本v8.9.1,但在部署以下代码时出现此错误: Function load error: Code in file index.js can't be loaded. Is there a syntax error in your code? Detailed stack trace: /user_code/index.js:550 async function deleteQueryBatch(db, query, batchSize, results) {

我使用的是Node的最新版本v8.9.1,但在部署以下代码时出现此错误:

Function load error: Code in file index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/index.js:550
  async function deleteQueryBatch(db, query, batchSize, results) {
        ^^^^^^^^

SyntaxError: Unexpected token function
代码(获取错误需要伪函数):

如何部署异步函数?我在Evennode上的服务器上没有收到此错误。

,这意味着它不支持异步/本机等待。如果您想使用某种形式的async/await,那么必须将ES7或TypeScript传输到ES6中,以便它可以在云函数提供的节点容器中运行。transpiler应该使用Promissions将async/await转换为等效代码


团队正在研究是否也提供Node8 LTS。

由于NodeJS 8.x现在是LTS,它应该可以工作了,对吗

当我在谷歌云控制台中输入“node--version”时,它会显示8.5.0作为node的版本

但是,当我通过“gcloud beta functions deploy”部署脚本时,在使用第一个“wait”的脚本位置会得到一个“SyntaxError:Unexpected identifier”


那么,在谷歌云中是否禁用了异步/等待功能?

在通过谷歌云平台部署异步功能时,我遇到了这个错误。尽管我在本地运行了一个较新的NodeJS版本,但我还是部署为v6。您可以将功能部署为NodeJS v6或v8。截至2019年1月,v6是默认选择,需要在部署前选择v8(Beta版)。

否您可以看到自己的本地节点版本,而不是谷歌版本。看道格的链接,它仍然是6.x.Ahm。。。当我在cloud.google.com上(在网站上!)进入云控制台时,技术上不可能访问我的本地控制台/节点安装并提供我的本地节点版本。另外,我的本地节点版本是8.9.1,而不是云控制台中打印的8.5.0。所以8.5.0版本绝对来自谷歌云。
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const db = admin.firestore()

exports.some = functions.firestore.document('x/{x}').onCreate(event => {

})

function deleteCollectionAndReturnDeletedDocs(db, collectionRef, batchSize) {
    return deleteQueryBatch(db, collectionRef.limit(batchSize), batchSize, []);
  }
  async function deleteQueryBatch(db, query, batchSize, results) {
    const snapshot = await query.get();
    if (snapshot.size > 0) {
      let batch = db.batch();
      snapshot.docs.forEach(doc => {
        if (doc.exists) {
          results.push(doc.data())

        };
        batch.delete(doc.ref);
      });
      await batch.commit();
    }
    if (snapshot.size >= batchSize) {
      return deleteQueryBatch(db, query, batchSize, results);
    } else {

      return results;
    }
  }