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

Set output filename/extension

Open archy-bold opened this issue 11 months ago • 2 comments

Is your feature request related to a problem? Please describe.

Getting the following error when trying to run a build in an ESM project:

✖ Unhandled exception in handler 'graphql'.
✖ ReferenceError: module is not defined in ES module scope
  This file is being treated as an ES module because it has a '.js' file extension and '/home/simon/Development/west-app/web/.esbuild/.build/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

Describe the solution you'd like

It seems this is fixed by giving the output file a .cjs extension. It would be great to specify the extension/filename as an option.

archy-bold avatar Jul 13 '23 22:07 archy-bold

Looks like this is possible with the following:

custom:
  esbuild:
    outExtension:
      ".js": .cjs

But perhaps it could be documented?

archy-bold avatar Jul 14 '23 09:07 archy-bold

@archy-bold this settings duplicate output with a .js and .mjs file. It's not possible to only export with .mjs extension ?

throrin19 avatar Dec 27 '23 16:12 throrin19