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

Support for ESM Import/Exports for NodeJS

Open logicalphase opened this issue 7 years ago • 5 comments

Issue Summary

I'm working on a ES6 project using lit-element, and need to add a contact form to it connected to our SendGrid account API. Attempted to add a ES Module Import statement, but it appears that the current release does not support it.

Steps to Reproduce

  1. npm i @sendgrid/mail
  2. Exported .env with API key.
  3. import {MailService} from '@sendgrid/mail'
const sgMail = MailService;
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
  const msg = {
   to: '[email protected]',
   from: '[email protected]',
   subject: 'Sending with SendGrid is Fun',
   text: 'and easy to do anywhere, even with Node.js',
   html: '<strong>and easy to do anywhere, even with Node.js</strong>',
 };
 sgMail.send(msg);

Error returned: _Uncaught (in promise) SyntaxError: The requested module '../../node_modules/@sendgrid/mail/src/mail.js' does not provide an export named 'MailService'_

I also tried to import 'mailer' with same result.

Technical details:

  • sendgrid-nodejs Version: 6.3.1
  • Node.js Version: 10.0.0
  • NPM Version: 6.4.1
  • Polymer Lit-Element 0.6.0

logicalphase avatar Sep 19 '18 17:09 logicalphase

Hello @hyperpress,

The officially supported usage is documented here.

I've added your request to our backlog for further investigation.

If you have any other information that could help us add support for this functionality, please let us know.

Thanks!

With Best Regards,

Elmer

thinkingserious avatar Sep 28 '18 03:09 thinkingserious

I'm checking in after nine months to see if there's been any consideration for adding support for ES Module, A'la:

import {MailService} from '@sendgrid/mail'

ES Modules are almost universally supported in NPM ecosphere.

logicalphase avatar Jul 13 '19 03:07 logicalphase

Hello, I am also interested by ESM support, I work with Reaction Commerce which run under node 12. Node 6, 7, 8 is a little outdated.

ghost avatar Mar 19 '20 12:03 ghost

:phone: ring ring! twilio, sendgrid: 2019 is calling!

i worked around it like this

  1. in my tsconfig.json, i enabled
    "allowSyntheticDefaultImports": true,
    
  2. that enabled me to import the commonjs via a synthetic default import
    import sendgridMail from "@sendgrid/mail"
    

edit: i just had an unbelievably bad experience with sendgrid, where they permanently closed my account due to "2 weeks of inactivity" -- and their support portal is broken with a redirect loop -- email support refuses to reopen my account, they want me to create a new email address just to sign up with a new account -- no -- so i threw out the sendgrid code i wrote for my app, abandoned this library, and signed up for mailgun instead, and am now using mailgun-js, which uses the same commonjs workaround as above

chase-moskal avatar Jun 16 '21 06:06 chase-moskal