doteric / funpack

Functions Packager (for AWS Lambdas for example)
https://www.npmjs.com/package/funpack
6 stars 0 forks source link

AWS lambda esm builds #18

Closed emcfarlane closed 1 year ago

emcfarlane commented 1 year ago

Thanks for the project! 🙏 The "type": "module" isn't passed down to package.json on built functions. AWS lambda thinks the module is a commonJS module and fails to parse.

Another option tried is editing the esbuild ext:

      "esbuildConfigOverride": {
        "format": "esm",
        "target": "node18",
        "outExtension": {
          ".js": ".mjs"
        }
      },
emcfarlane commented 1 year ago

Just saw this example: https://github.com/doteric/funpack/blob/master/examples/mjs-extension/package.json 👍

doteric commented 1 year ago

Hey @emcfarlane, yes, exactly, you can override all the configuration options of esbuild using the funpack configuration. I would like to also add presets for specific setups, but no ETA's yet so you have to override the esbuild config.

You can also use the "type": "module" from the package.json, here is an example: https://github.com/doteric/funpack/blob/master/examples/module-splitting/package.json#L12
This configuration will also pass the type inside your package.json to the package.json in the output/bundle. packageFieldsToCopy is responsible for this to be exact.

Let me know if this answers your questions. If you have any other problems or ideas feel free to let me know.

emcfarlane commented 1 year ago

Thanks!