Support for ESM Import/Exports for NodeJS
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
-
npm i @sendgrid/mail - Exported .env with API key.
-
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
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
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.
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.
:phone: ring ring! twilio, sendgrid: 2019 is calling!
i worked around it like this
- in my tsconfig.json, i enabled
"allowSyntheticDefaultImports": true, - 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