找不到模块“ @ sendgrid / mail”

时间:2019-11-10 06:29:39

标签: twilio twilio-functions

我正在使用Sendgrid邮件包(https://www.npmjs.com/package/@sendgrid/mail)通过Twilio Serveless功能发送测试电子邮件。我已经配置了模块,在此处的“配置”仪表板中指定了正确的版本和模块。 https://www.twilio.com/console/functions/configure,但是当我部署功能并使用twilio cli运行它时,我得到了错误消息,

“消息”:“找不到模块'@ sendgrid / mail'”

我觉得这很奇怪,因为在“管理”选项卡下https://www.twilio.com/console/functions/manage选项卡下手动部署功能就像宝石一样。我想念什么吗?

还是无服务器API当前不支持此功能? (当我手动部署该功能时,相同的程序包配置也起作用)

2 个答案:

答案 0 :(得分:2)

基于Twilio GUI控制台的功能与基于API的功能是不同的。您可以在此处找到更多详细信息。

Beta limitations, known issues and limits

您可以使用npm install添加npm模块,如此处所述。

Twilio Serverless Toolkit - Deploy a Project

“ package.json的依赖项字段中列出的任何依赖项都会自动安装在部署中。”

如果使用Visual Studio Code方法,则可以执行相同操作。

答案 1 :(得分:0)

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: 'test@example.com',
  from: 'test@example.com',
  subject: 'Sending with Twilio 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>',
};
//ES6
sgMail
  .send(msg)
  .then(() => {}, console.error);
//ES8
(async () => {
  try {
    await sgMail.send(msg);
  } catch (err) {
    console.error(err.toString());
  }
})();