Exception while invoking method X has no method Y

I get this while trying to send an email with sendgrid. I’m using the https://github.com/DavidBrear/meteor-sendgrid and meteor “email” package.

Exact error message:

20160128-17:05:21.028(1)? Exception while invoking method ‘sendEmail’ { stack: ‘TypeError: Object [object Object] has no method ‘send’\n at [object Object].Meteor.methods.sendEmail (server/method/email.js:46:11)\n at [object Object].methodMap.(anonymous function) (packages/meteorhacks_kadira/lib/hijack/wrap_session.js:164:1)\n at maybeAuditArgumentChecks (livedata_server.js:1698:12)\n at livedata_server.js:708:19\n at [object Object]..extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)\n at livedata_server.js:706:40\n at [object Object]..extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)\n at livedata_server.js:704:46\n at tryCallTwo (C:\Users\Anders\AppData\Local\.meteor\packages\promise\0.5.1\npm\node_modules\meteor-promise\node_modules\promise\lib\core.js:45:5)\n at doResolve (C:\Users\Anders\AppData\Local\.meteor\packages\promise\0.5.1\npm\node_modules\meteor-promise\node_modules\promise\lib\core.js:171:13)’,
I20160128-17:05:21.029(1)? source: ‘method’ }

This code has worked a couple of days ago so I think it’s related to some other package conflicting with this or eaven worse.

The Method:

Meteor.methods({
sendEmail: function (email) {
if(!email.type) {
email.type = ‘text’;
}
check([email.type, email.from, email.to, email.subject, email.body], [String]);
this.unblock();

  if(email.type && email.from && email.to && email.subject && email.body) {
  	Meteor.Sendgrid.send({
  		to: email.to, from: email.from, subject: email.subject, text: email.body
  	});
  } else {
  	throw new Meteor.Error("Error", "E-mail was not sent");
  }

}
});

I have a server startup script that sets a correct smtp-url in “MAIL_URL” Env-variable.

config.js

Meteor.startup(function(){
Meteor.Sendgrid.config({
username: ‘’,
password: ‘’
});
});

sendgrid.js

Meteor.Sendgrid = {
config: function(options){
username = options[‘username’];
password = options[‘password’];
host = ‘@smtp.sendgrid.net’;
port = ‘465’;
process.env.MAIL_URL = ‘smtp://’ + username + ‘:’ + password + host + ‘:’ + port + ‘/’;
},
send: function(options){
Email.send(options);
}
}

I have tested and replaced “Meteor.Sendgrid.send” with “Email.send” and also removed the “email” package and added it again but still the same result.

How do I do more advanced debugging to find the root cause of this in my Meteor app?

Thankfull for all your help!

In your method add a console.log(Meteor.Sendgrid) to see what’s being returned for the Meteor.Sendgrid object. Since whatever it is doesn’t have a send function, finding out what it is first will help with troubleshooting.

It says

{ config: [Function], send: [Function] }

So it seems it’s something there after all…

I tried removing the meteorhacks:kadira package as it was mentioned in the error message but then I got:

I20160128-21:21:45.934(1)? Exception while invoking method ‘sendEmail’ TypeError: Object [object Object] has no method 'send’
I20160128-21:21:45.935(1)? at [object Object].Meteor.methods.sendEmail (server/method/email.js:45:11)
I20160128-21:21:45.935(1)? at maybeAuditArgumentChecks (livedata_server.js:1698:12)
I20160128-21:21:45.935(1)? at livedata_server.js:708:19
I20160128-21:21:45.936(1)? at [object Object]..extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20160128-21:21:45.936(1)? at livedata_server.js:706:40
I20160128-21:21:45.938(1)? at [object Object].
.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20160128-21:21:45.939(1)? at tryCallTwo (C:\Users\Anders\AppData\Local.meteor\packages\promise\0.5.1\npm\node_modules\meteor-promise\node_modules\promise\lib\core.js:45:5)
I20160128-21:21:45.938(1)? at livedata_server.js:704:46
I20160128-21:21:45.939(1)? at doResolve (C:\Users\Anders\AppData\Local.meteor\packages\promise\0.5.1\npm\node_modules\meteor-promise\node_modules\promise\lib\core.js:171:13)
I20160128-21:21:45.941(1)? at new Promise (C:\Users\Anders\AppData\Local.meteor\packages\promise\0.5.1\npm\node_modules\meteor-promise\node_modules\promise\lib\core.js:65:3)

Are you trying to run your method on the client? Email will only work server side. You’re probably getting this error from the client stub. Try wrapping your method contents in a this.isSimulation check:

...
if (!this.isSimulation) {
  if (email.type && email.from && email.to && email.subject && email.body) {
    Meteor.Sendgrid.send({
      to: email.to, from: email.from, subject: email.subject, text: email.body
    });
  } else {
    throw new Meteor.Error('Error', 'E-mail was not sent');
  }
}
...

No I’m calling the method from the client and execute the send on teh server side.

if (!this.isSimulation)
gave the same result as before

Any other suggestion hwilsson? I’m kind of stuc here… :confused:

Finally figured it out, I had named a collection “Email” and that had “overwritten” the method. I guess there would be really nice if there could be somekind of check if diffrent kind of things overwrite each other.

The way I found it was trough “consol.log(Email)” and checked the differences between my app and a new app with just the email functionallity.

Just mentioning it if someone els stumbles up on the same type of error. :relaxed:

1 Like