Closed nickcox closed 1 year ago
This code needs to be aware if the package.json has "type": "module"
and if it is... then it needs to use dynamic import import(path)
instead, this is allowed from node v12.20 and onwards from commonjs
https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/c31c41ffe5f2f03ae9e8589b96f3b005e2bb8a4a/src/utils/UserFunction.ts#L70-L87
but b/c you use typescript and downlevel everything to commonjs 👎 so it outputs something like __importStar(require('module')))
after you have compiled the source, then you need to use this to prevent typescript from rewriting import to require:
const _importDynamic = new Function('modulePath', 'return import(modulePath)')
_importDynamic(path)
(Imo i think you should ditch typescript, switch to ESM and not transpile anything - but this is just my opinion)
Afaict, there's no way to use an ES module based hander right now.
It would be awesome to have one less build step. Just wondering if this is on the roadmap?