Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot read property 'gmail' of undefined

let fs = require('fs');
let google = require('googleapis');

getMessage(userId, messageId, callback) {
    let gmail = this.getGmailService();
    var request = google.client.gmail.users.messages.get({
        'userId': userId,
        'id': messageId
    });
    request.execute(callback);
}

when I call this method from a spec

getMessage('[email protected]', '15934550ay626ud09')

it spits out the following error

TypeError: Cannot read property 'gmail' of undefined

any comments/suggestions?

like image 983
CodeJockey Avatar asked Mar 12 '26 19:03

CodeJockey


1 Answers

There are 3 options: 1. You didn't install the googleapis node module. 2. You didn't import it well. 3. You didn't use it well.

Option 1 fix: Install the googleapis node module: yarn add googleapis

Option 2 fix: In the new version of googleapis (V26) I needed to change my import line to the following: var {google} = require('googleapis');

Option 3 fix: You are calling it via google.client.gmail, perhaps use just google.gmail

like image 150
walla Avatar answered Mar 14 '26 07:03

walla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!