SReddy
SReddy

Reputation: 11

Firebase function TypeError: Cannot read property 'stack' of undefined for Action on google

I am using Firebase cloud functions as webhook for my action-on-google dialogflow fulfilment.

My index.js file is as below

'use strict';

process.env.DEBUG = 'actions-on-google:*';

var requestcall = require('request');
var date = require('date-and-time');
var promise = require('promise');
var AmazonDateParser = require('amazon-date-parser');
var moment = require('moment-timezone');

var accountnum;
var accessToken;
var timePeriod;
var acctnums =[];


// Create functions to handle requests here
const WELCOME_INTENT = 'input.welcome';  // the action name from the Dialogflow intent
const NUMBER_INTENT = 'account_number';  // the action name from the Dialogflow intent
const NUMBER_ARGUMENT = 'number'; // the action name from the Dialogflow intent

const OUT_CONTEXT = 'output_context';
const ACCOUNT_ARG = 'info';
const ACCOUNT_NUM = 'myAccountNum';
const AccountNums = 'AccountNums';
const CURRENCY_SYMBOL = 'CurrencySymbol';
const TIME_ZONE = 'TimeZone';
const STATS_ARG = 'nextStatsData';



const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');

const {
  SimpleResponse,
  BasicCard,
  Image,
  Suggestions,
  Button
} = require('actions-on-google');

const app = dialogflow(

{debug: true,clientId: 'xxxxxxxxxxx.apps.googleusercontent.com'});

 app.middleware((conv) => {
    
   });



  


app.intent('Default Welcome Intent', (conv) => {
   
  
  console.log('Request headers: ' + JSON.stringify(conv.headers));
  console.log('Request body: ' + JSON.stringify(conv.body));
  accessToken =conv.body.originalDetectIntentRequest.payload.user.accessToken;
   console.log('accessToken: ' + accessToken);
 
  if (accessToken !== null) {
      
      
      return  getaccountDetails(conv).then((entity)=>{
      return getMessageFromAccount(entity,conv);
      });
     
       
    
  }
  else{
      
     return conv.close(new SignIn('To get your account details'));
     
      
  }
 
  
  });
exports.stats = functions.https.onRequest(app);

My package.json file is as below

  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase serve --only functions",
    "shell": "firebase experimental:functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "actions-on-google": "^2.12.0",
    "amazon-date-parser": "^0.1.5",
    "date-and-time": "^0.6.3",
    "dialogflow": "^0.6.0",
    "express": "^4.17.1",
    "firebase-admin": "^6.5.1",
    "firebase-functions": "^3.9.0",
    "moment-timezone": "^0.5.31",
    "node-pre-gyp": "^0.15.0",
    "promise": "^8.1.0",
    "request": "^2.88.2"
  },
  "engines": {
    "node": "10"
  },
  "devDependencies": {
    "firebase-functions-test": "^0.2.1"
  },
  "private": true,
  "version": "1.0.0",
  "main": "index.js",
  "author": "",
  "license": "ISC"
}

I am getting the following error while testing my actions-on-google

TypeError: Cannot read property 'stack' of undefined
    at standard.then.catch (/workspace/node_modules/actions-on-google/dist/framework/express.js:37:32)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Error is not in my index.js. The error is in actions-on-google npm modules library at express.js.

I deleted my node modules and installed again and rebuild the code. still same error coming.

Please help me in solving this issue.

Upvotes: 1

Views: 665

Answers (1)

Prisoner
Prisoner

Reputation: 50701

If you're using Cloud Functions for Firebase - I wouldn't have expected that code to be called at all.

I suspect that including the "express" package in your dependencies is bringing in an outside version of express and this is confusing the actions-on-google library, which has the express types separately defined. The a-o-g library uses this library for those who are using express directly to setup the route, and it shouldn't be necessary if you're using Cloud Functions.

I would suggest removing the package, and making sure it is not in your node modules.

Upvotes: 1

Related Questions