I have a library foo which is written with ES6, import/export and in Typescript.
I have an app bar which uses foo. bar is also written with exports and Typescript. I would like to get bar running on AWS Lambda.
From what I can tell, I cannot use import/export in Lambda (with runtime node 14.x) as
export const handler = async () => {...};
Will error, but
exports.handler = async () => {...};
Will not.
So within my tsconfig I have set:
"target": "ES5", (or ES6)
"module": "CommonJS",
under the compiler options.
With this, running on Lambda I get errors since it now tries to require the foo library and says it must use import.
How can I achieve my end goal?
As I see it there are 3 options, none of which I know much about since I am still new to the JS nuances.
- Have my
barapp transpile, or use webpack, or whatever the tool may be to replicateimportin cjs. - Have my
foolibrary also include a CJS distrobution (started doing this and got many errors from the hoops I had to get through to make the library work in es6). - I'm missing something in Lambda / Typescript which will make this easy.