繁体   English   中英

找不到模块“@sendgrid/mail”

[英]Cannot find module "@sendgrid/mail"

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

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

我发现这很奇怪,因为在“管理”选项卡下手动部署了function,https://www.twilio.com/console/functions/manage选项卡就像一个 gem。 我错过了什么?

还是无服务器 API 目前不支持这个? (当我手动部署该功能时,相同的 package 配置有效)

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

Beta 版限制、已知问题和限制

您可以使用 npm 安装添加 npm 模块,详见此处。

Twilio 无服务器工具包 - 部署项目

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

如果您使用Visual Studio Code方法,您也可以这样做。

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());
  }
})();

只需使用:

yarn add @sendgrid/mail

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM