Hello,
I am trying to use serverless functions to autogenerate some certificate images. I have run into the following error:
{
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module '@sendgrid/mail'\nRequire stack:\n- /var/task/src/helpers/generateCertificate.js\n- /var/task/src/sendCertificates.js\n- /var/task/sendCertificates.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
"trace": [
"Runtime.ImportModuleError: Error: Cannot find module '@sendgrid/mail'",
"Require stack:",
"- /var/task/src/helpers/generateCertificate.js",
"- /var/task/src/sendCertificates.js",
"- /var/task/sendCertificates.js",
"- /var/runtime/UserFunction.js",
"- /var/runtime/index.js",
" at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
" at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
" at Object.<anonymous> (/var/runtime/index.js:43:30)",
" at Module._compile (internal/modules/cjs/loader.js:1015:30)",
" at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)",
" at Module.load (internal/modules/cjs/loader.js:879:32)",
" at Function.Module._load (internal/modules/cjs/loader.js:724:14)",
" at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
" at internal/main/run_main_module.js:17:47"
]
}
The reason this bug is so strange is that in another serverless function (under the same site name) I have used the sendgrid module with no issues, how can it stop recognizing it in one function and not the other?
Here is how I am requiring the modules in the working function:
const sgMail = require("@sendgrid/mail");
var moment = require('moment-timezone');
const getRegistrations = require('./getRegistrations');
const formattedReturn = require('./formattedReturn');
const formattedError = require('./formattedError');
Here is how I am requiring the code in the function that is not working:
const sgMail = require("@sendgrid/mail");
var moment = require("moment-timezone");
const formattedReturn = require('./formattedReturn');
const getRegistrations = require("./getRegistrations");
const { createCanvas, loadImage } = require("canvas");
require("dotenv").config();
The issue isn’t just for sendgrid, however, it is any of those modules that I decide to place at the top of the code (canvas, dotenv, moment-timezone).
Here is the package.json file:
Solutions that I have attempted and that have not worked:
- Deleting node_modules from the repo
- Adding .default at the end of all the requires (require(“canvas”).default)
- Using CI= npm install as the build command
Any help would be appreciated