找不到模块“@sendgrid/mail”
Cannot find module "@sendgrid/mail"
我正在使用 Sendgrid 邮件包(https://www.npmjs.com/package/@sendgrid/mail) to send a test email using the Twilio Serveless functions. I have configured the module, specifying the correct version and module in the configure dashboard here. https://www.twilio.com/console/functions/configure 但是当我部署我的函数并使用 twilio cli 运行 它时,我收到错误消息,
"message":"Cannot find module '@sendgrid/mail'"
我觉得这很奇怪,因为在“管理”选项卡下手动部署该功能,https://www.twilio.com/console/functions/manage 选项卡的工作方式类似于 gem。我错过了什么?
或者无服务器 API 目前不支持这个? (当我手动部署函数时相同的包配置有效)
基于 Twilio GUI 控制台的函数与基于 API 的函数是独立且不同的。您可以在此处找到更多详细信息。
Beta limitations, known issues and limits
您可以使用 npm install 添加 npm 模块,详见此处。
Twilio Serverless Toolkit - Deploy a Project
"Any dependency that is listed in the dependencies field in your package.json will automatically be installed in your deployment."
如果您使用 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());
}
})();
我正在使用 Sendgrid 邮件包(https://www.npmjs.com/package/@sendgrid/mail) to send a test email using the Twilio Serveless functions. I have configured the module, specifying the correct version and module in the configure dashboard here. https://www.twilio.com/console/functions/configure 但是当我部署我的函数并使用 twilio cli 运行 它时,我收到错误消息,
"message":"Cannot find module '@sendgrid/mail'"
我觉得这很奇怪,因为在“管理”选项卡下手动部署该功能,https://www.twilio.com/console/functions/manage 选项卡的工作方式类似于 gem。我错过了什么?
或者无服务器 API 目前不支持这个? (当我手动部署函数时相同的包配置有效)
基于 Twilio GUI 控制台的函数与基于 API 的函数是独立且不同的。您可以在此处找到更多详细信息。
Beta limitations, known issues and limits
您可以使用 npm install 添加 npm 模块,详见此处。
Twilio Serverless Toolkit - Deploy a Project
"Any dependency that is listed in the dependencies field in your package.json will automatically be installed in your deployment."
如果您使用 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());
}
})();