[英]Cannot find module @sendgrid/mail in Cloud Functions (Typescript)
I want to test out SendGrid to automate sending emails which will be triggered from Firebase Cloud Functions.我想测试 SendGrid 以自动发送将从 Firebase Cloud Functions 触发的电子邮件。 I use Typescript to write the Cloud Functions.
我使用 Typescript 来编写 Cloud Functions。 But for some reason, even after following all the steps, I keep getting an error that says "Cannot find module @sendgrid/mail".
但出于某种原因,即使在执行了所有步骤之后,我仍然收到“找不到模块@sendgrid/mail”的错误消息。 Here is a snippet of the code:
这是代码片段:
The error that I keep getting in the Cloud Function logs is as follows:我在云 Function 日志中不断收到的错误如下:
I've also checked my node_modules folder, and my package.json file.我还检查了我的 node_modules 文件夹和我的 package.json 文件。 Both has @sendgrid/mail in it, so I really don't know how to fix it.
两者都有@sendgrid/mail,所以我真的不知道如何修复它。 Any help would be greatly appreciated.
任何帮助将不胜感激。
The error seems to be related to a dependency resolution issue or not correctly syntax placed., where when the code it is trying to find for a module to fetch and use the dependencies for variables and functions.It looks like there is small syntax issue where the msg section has a missing end after bracket };
该错误似乎与依赖项解析问题或语法放置不正确有关。当它试图为模块查找代码以获取和使用变量和函数的依赖项时。看起来存在小语法问题msg 部分在括号
};
.I would recommend you try to make changes to your code according to the following example and see if that helps: .I would recommend you try to make changes to your code according to the following example,看看是否有帮助:
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(functions.config().sendgrid.apikey); // See the doc for the config: https://firebase.google.com/docs/functions/config-env // The API key is securely stored as a Cloud Function configuration item
const msg = {
to: 'test@example.com',
from: 'test@example.com',
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>', };
Also check these useful links for more information:另请查看这些有用的链接以获取更多信息:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.