0

Anyone encountered same issue as mine?

when I'm using async function with my script I encounter an error like 'sync functions' is only available in ES8 (use 'esversion:8')'

I already tried to input the /*esversion: 8 */ also /* jshint esversion: 8 */ at the first line of my script

May I know what I need to check on my script for me to use the async?

/*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"
  }
}
Min Max
  • 1
  • 3
  • When you create fulfillment inline editor, the original source code was made in CloudFunctions in Google Cloud. You can check the version of node and package.json file as well. It may more helpful us to add node version and package.json file. – Peter Oct 11 '22 at 13:49

1 Answers1

0

There is no clear answer here, but several things you can try to make it work.

  1. In package.json make sure you are calling compatible packages and setting the nodeJS engine explicitly. Here's my current configuration. Carefully update packages as it could break some working code.

    { "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": "12" }, "scripts": { "start": "firebase serve --only functions:dialogflowFirebaseFulfillment", "deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment" }, "dependencies": { "actions-on-google": "^2.13.0", "firebase-admin": "^9.5.0", "firebase-functions": "^3.13.2", "dialogflow": "^1.2.0", "dialogflow-fulfillment": "^0.6.1", "@google-cloud/bigquery": "^5.5.0", "axios": "0.21.1"
    } }

  2. In my code I have it set up like this:

    'use strict'; / jshint esversion: 8 /

    Some will tell you jshint comes before - mine works after. I don't know if it matters but you can try changing it around.

  3. Enable the Bigquery API and Billing on your account in Google Cloud Console if not yet enabled. You have access to a free tier but storage costs will incur depending on the size of your data

  4. In inline editor return results of your async function or call it. You can add the line below in main() after the query function.

    return query() ;

    OR

    query;

  5. Write a new function above main and before intentMap (if using dialogflow fullfillment) that exploits async or promises.

    function getSnum(agent) { return main().then(results=> {console.log(results.length);}) }

  • May I know if possible to develop a connection between dialogflow to bigquery without using async function? – Min Max Oct 13 '22 at 12:49