Sendgrid-nodejs: Sendgrid Integration errors with Node v9.10.1

Created on 15 Jun 2018  路  9Comments  路  Source: sendgrid/sendgrid-nodejs

I have Node v9.10.1 and NPM v6.1.0. I get below error from sendgrid:

/home/vcap/app/node_modules/@sendgrid/mail/src/classes/mail-service.js:6
const {Client} = require('@sendgrid/client');
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object. (/home/vcap/app/node_modules/@sendgrid/mail/src/mail.js:6:21)
As per the documentation, sendgrid library supports node version > v6.
Please suggest what is going wrong here.

waiting for feedback question

All 9 comments

Hello @MayMaria,

Can you please try: const Client = require('@sendgrid/client');

Thanks!

With Best Regards,

Elmer

Also having this issue. Not using the client library, only @sendgrid/mail

Hello @dylankbuckley,

Could you please tell me a bit about your stack, including how you installed this SDK so that I can try to reproduce?

Thanks!

With Best Regards,

Elmer

@thinkingserious @MayMaria This was fixed by upgrading to v. 6.3.1 of @sendgrid/mail. I was previously running on 6.1.1

Thanks for sharing your solution @dylankbuckley!

@MayMaria,

Have you been able to resolve your issue?

I'm having the same issue and I'm running Node 11.2.0 + @sendgrid/client 6.4.1.
Everyone seems to fix it by upgrading but I'm stuck with it.

@jorgeqscholz could you clarify what is happening? Are seeing the same error as the OP?

If you're attempting the same syntax var {Client} = require(...), see if removing the curly brackets in your variable declaration resolves the issue?

@jorgeqscholz could you clarify what is happening? Are seeing the same error as the OP?

If you're attempting the same syntax var {Client} = require(...), see if removing the curly brackets in your variable declaration resolves the issue?

It doesn't resolve the issue. It says "TypeError: Client is not a constructor at new MailService"

this.setClient(new Client());
               ^

Looks like a mismatch between the client and mail version from 6.1.x to 6.2.x. Can you verify you're using the correct versions for both in your lock file?

Was this page helpful?
0 / 5 - 0 ratings