Sendgrid-nodejs: setApiKey is not a function

Created on 18 Jun 2018  ·  4Comments  ·  Source: sendgrid/sendgrid-nodejs

Issue Summary

Hi,
Not sure if this is an issue or a fault on my side, but i can't use sendgrid library : I'm having this exception : setApiKey is not a function ,
I'm using TypeScript 2.9.1 but I don't think the types are the problem.

Steps to Reproduce

Pretty straightforward :

import * as sendGrid from "@sendgrid/mail"

sendGrid.setApiKey($SENDGRID_API_KEY)
mail = { // some mail object }

sendGrid.send(mail)

Just like in the docs.
If someone could enlighten me, that'd be really appreciable,
Thanks,

Technical details:

  • @sendgrid/mail Version: 6.3.0
  • Node.js Version: 8.11.2
unknown or a help wanted question

Most helpful comment

Sorry,
I just mis-imported the module :
import sgMail from "@sendgrid/mail" works fine

All 4 comments

Sorry,
I just mis-imported the module :
import sgMail from "@sendgrid/mail" works fine

@Loriot-n you saved my day! I also mis-imported the module and have been looking at it all day, but now it works.
Thanks again!

@Loriot-n : Hi, how did you import like that?

I also use import sgMail from '@sendgrid/mail'

But when I tried to run with babel-node:

Error: Cannot find module '../sendgrid/mail'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/Users/piavgh/Desktop/Dev/src/helpers/mail.js:3:1)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Module._compile (/Users/piavgh/Desktop/Dev/jetdyno/Code/performflow-api/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Object.newLoader [as .js] (/Users/piavgh/Desktop/Dev/jetdyno/Code/performflow-api/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:600:32)
[nodemon] app crashed - waiting for file changes before starting...

I resolved this by changing import * as sendgrid from '@sendgrid/client'; to const client = require('@sendgrid/client');

Was this page helpful?
0 / 5 - 0 ratings