I have a module I wrote (which is installed via npm from a private repo) that the following structure:
email.ts, utils.ts, index.ts, (some other files)
On my email.ts I have the following function:
export default function sendEmail(toEmail: string, subject: string, content: string): any {
let helper = SendGrid.mail;
let from_email: any = new helper.Email(process.env.FROM_EMAIL);
let to_email: any = new helper.Email(toEmail);
let helperContent: any = new helper.Content("text/plain", content);
let mail: any = new helper.Mail(from_email, subject, to_email, helperContent)
var request = SendGrid.emptyRequest({
method: "POST",
path: "/v3/mail/send",
body: mail.toJSON()
});
//This performs the request with a promise
SendGrid.API(request).then((response: any) => {
//Deal with output as needed
console.log("email was sent!!");
}).catch((err: any) => {
//log.error(err);
});
}
export * from "./email";
export * from "./errors";
export * from "./logger";
export * from "./objectUtils";
export * from "./queryFilter";
export * from "./templateEngine";
export * from "./utils";
import * as Utils from "my-utils";
Utils.sendEmail(email, subject, content);
"Cannot read property 'sendEmail' of undefined"
Try changing
export default function sendEmail
to just
export function sendEmail