sendgrid-nodejs icon indicating copy to clipboard operation
sendgrid-nodejs copied to clipboard

setApiKey is not a function

Open Loriot-n opened this issue 8 years ago • 4 comments

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

Loriot-n avatar Jun 18 '18 07:06 Loriot-n

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

Loriot-n avatar Jun 18 '18 11:06 Loriot-n

@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!

linocatucci avatar Feb 15 '19 16:02 linocatucci

@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...

piavgh avatar Aug 17 '19 12:08 piavgh

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

jbistis avatar Sep 01 '19 18:09 jbistis