skip to Main Content

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:
enter image description here

The error that I keep getting in the Cloud Function logs is as follows:
enter image description here

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


  1. 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:

    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: '[email protected]', 
    from: '[email protected]', 
    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:

    Login or Signup to reply.
  2. 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!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search