Q:

accessing lambda module with nodejs module.exports

I am writing an application in nodejs-typescript using the serverless framework. I am trying to compartmentalize my code by exporting some generic functions as modules with a simple log (to test the concept works). I have two files. Service-alerts.ts and MailerClass.ts. It seems that I am constantly getting a syntax error when deploying my applications. I am very frustrated. Most tutorials are not using serverless, only node. Can you help me solve this?
service-alert.ts (function that gets executed):
import generateShortname from './MailerClass';
export const handler = async (_event, _context) => {
    generateShortname("hello");
    return;
};

Mailerclass (file that logs value):
export const generateShortname = (value) => {
    console.log(value);
};

Error log from AWS Lambda execution:
Response:
    {
        "errorType": "Runtime.UserCodeSyntaxError",
        "errorMessage": "SyntaxError: Unexpected identifier",
        "trace": [
             "Runtime.UserCodeSyntaxError: SyntaxError: Unexpected identifier",
             "    at _loadUserApp (/var/runtime/UserFunction.js:98:13)",
             "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
             "    at Object.<anonymous> (/var/runtime/index.js:45:30)",
             "    at Module._compile (internal/modules/cjs/loader.js:778:30)",
             "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)",
             "    at Module.load (internal/modules/cjs/loader.js:653:32)",
             "    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)",
             "    at Function.Module._load (internal/modules/cjs/loader.js:585:3)",
             "    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)",
             "    at startup (internal/bootstrap/node.js:283:19)"
        ]
    }

A:

A few things jump out at me right away - You're using typescript, but aren't using any types. Although your code is vanilla JS, your import statement is ES6 (which I don't think is supported in node yet). I'd try replacing your import statement (es6) with a vanilla const generateShortname = require('./MailerClass');.
If that doesn't work, try compiling your typescript before deploying it. There are a lot of Serverless Framework plugins that can help with that. I'd recommend trying serverless-typescript, or if you'd prefer you can use serverless-webpack.

