dialogflow实现内联编辑器中的异步函数错误



有人遇到和我一样的问题吗?

当我在脚本中使用异步函数时,我会遇到一个错误,比如"同步函数"仅在ES8中可用(使用"esversion:8"('

我已经尝试输入/*esversion: 8 */而且/* jshint esversion: 8 */在我的脚本的第一行

我可以知道我需要在脚本上检查什么才能使用异步吗?

/*esversion: 8 */   << I also tried this  /* jshint esversion: 8 */  still the error not resolve. 
'use strict';
function main() {

const {BigQuery} = require('@google-cloud/bigquery');
async function query () {   << 'sync functions' is only available in ES8 (use 'esversion:8')'

const bigqueryClient = new BigQuery();
const sqlQuery = `SELECT * FROM `sample.dataset` LIMIT 1000;
const options = {
query: sqlQuery,

location: 'US',
params: {serialnumber: 'test', min_word_count: 250},
useQueryCache: false,
};

Package.json

{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "10",
"jshintConfig":{"esversion": 8, "strict": "implied", "devel": true, "node": true, "globals": {} }
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "^2.2.0",
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.5.0",
"@google-cloud/bigquery": "^0.12.0"
}
}

这里没有明确的答案,但有几件事你可以尝试让它发挥作用。

  1. 在package.json中,确保调用兼容的包并显式设置nodeJS引擎。这是我目前的配置。小心地更新包,因为它可能会破坏一些工作代码。

    {"name":"dialogflowFirebaseFulfillment";,"描述":"这是使用Cloud Functions for Firebase的Dialogflow代理的默认实现";,"版本":"0.0.1";,"私有":是的,"许可证":"Apache版本2.0";,"作者":"谷歌股份有限公司;,"发动机":{"节点":"12〃;},"脚本":{"开始":"firebase serve-only函数:dialogflowFirebaseFulfillment";,"部署":"firebase deploy-only函数:dialogflowFirebaseFulfillment;},"依赖关系":{"谷歌上的动作":"2.13.0";,"firebase管理员":"9.5.0";,"firebase函数":"3.13.2";,"对话流":"1.2.0";,"对话流实现":"0.6.1〃;,"google cloud/bigquery":"5.5.0";,"axios":"0.21.1〃
    }}

  2. 在我的代码中,我把它设置成这样:

    "使用严格";/jshint esversion:8/

    有些人会告诉你jshint在之前,而我的在之后。我不知道这是否重要,但你可以试着改变一下。

  3. 如果尚未启用,请在Google云控制台中的帐户上启用Bigquery API和Billing。您可以访问免费层,但存储成本将根据您的数据的大小而产生

  4. 在内联编辑器中,返回或调用异步函数的结果。您可以在查询函数后面的main((中添加下面的行。

    return query((;

    查询;

  5. 在main之上和intetMap之前(如果使用dialogflow fullfilment(编写一个利用异步或promise的新函数。

    函数getSnum(代理({return main((.then(results=>{console.log(results.length(;}(}

最新更新