serverless-bundle icon indicating copy to clipboard operation
serverless-bundle copied to clipboard

Failing with `ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead`

Open arthurliebhardt opened this issue 3 years ago • 4 comments

Hello,

my lambda failing with the following error. Do I need to use import instead of require everywhere with serverless-bundle?

"ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: 53521"

Thank you and best,

arthurliebhardt avatar Mar 20 '22 11:03 arthurliebhardt

+1 on this. Any solution ?

vikram-rb avatar Mar 26 '22 13:03 vikram-rb

+1 on this. Any solution?

One solution which worked for me is to import / export all the direct imports (which are in the same folder or above for example) using ESM import / export. Also the handler needs to be exported either with export default const .... than also the handler needs to be named default in the serverless.yml or doing a const handlerName and then on the bottom export { handlerName } than the handler name can be the same in the serverless.yml.

Hope this helps.

arthurliebhardt avatar Mar 30 '22 10:03 arthurliebhardt

Any solution on this?

I'm also getting this error, in my case I'm using prisma4 with serverless-bundle, and my runtime is Node 16

srax47 avatar Aug 18 '22 13:08 srax47

Use esbuild-loader

Add following option to serverless.yml file

custom:
  bundle:
    esbuild: true

Puvipavan avatar Oct 11 '22 12:10 Puvipavan