For those who use serverless there is a plugin
@vibe I would like to thank you for your solution, it works! Because of that I made a plugin for those who use serverless. Follow the link: https://www.npmjs.com/serverless-esm-layer
Thank you for the plugin, @luisdemarchi. Have you managed to get the plugin to work successfully when your layers are built using Github Actions please? I get ERROR Error [ERR_MODULE_NOT_FOUND]: Cannot find package ... errors when I build the layer in GHA, but if I build my layers on my Mac then they work as expected.
@john-tipper Unfortunately I don't use github actions. I successfully tested it by direct deploying on mac, from semaphoreci.com and aws codepipeline.