I want to test out SendGrid to automate sending emails which will be triggered from Firebase Cloud Functions. I use Typescript to write the Cloud Functions. But for some reason, even after following all the steps, I keep getting an error that says "Cannot find module @sendgrid/mail". Here is a snippet of the code:
The error that I keep getting in the Cloud Function logs is as follows:
I’ve also checked my node_modules folder, and my package.json file. Both has @sendgrid/mail in it, so I really don’t know how to fix it. Any help would be greatly appreciated.
2
Answers
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
};
.I would recommend you try to make changes to your code according to the following example and see if that helps:Also check these useful links for more information:
I had this same issue, even while using the syntax mentioned in the other answer. The issue for me was that the sendgrid module was installed in the wrong directory. Try changing directories into the "functions" folder and running
npm install --save @sendgrid/mail
. Hope this helps!