Open keyvhinng opened 9 months ago
The problem here is that serverless-esbuild is assuming a CJS environment. However, I'm in the process of migrating to ESLint Flat Config, and so I've upgraded from v0.3.3 of esbuild-plugin-eslint
to v0.3.8 as a result of https://github.com/robinloeffel/esbuild-plugin-eslint/issues/11 (supporting v9 of eslint). As such, I've encountered the problem of importing ESM in CJS, thanks to the work from v0.3.4 (migration to ESM).
The ideal solution to this, would be to support ESBuild config files in ESM format (esbuild.config.mjs
, or "type": "module"
in our package.json
). This can be done thanks to the async import
function, but would require quite a bit of refactoring in order to use, since it introduces async into the mix...
In order to reduce the immediate burden, it might be worth using something like https://www.npmjs.com/package/promise-synchronizer to prevent the need to refactor and test the plugin in order to support async.
In the meantime, I'm going to continue to use .cjs
for my esbuild config, and use promise-synchronizer
in order to use the dynamic import to use esbuild-plugin-eslint
. This isn't ideal (the ideal solution would be the plugin supporting ESM), but it gets me back up and running.
Describe the bug I want to use ES modules and exclude @aws-sdk libraries from the bundle since those libraries are built-in by default on AWS Lambda
To Reproduce Steps to reproduce the behavior. If you have an example repository that would be even better:
files:
package.json :
serverless.yml :
esbuild.config.js :
But I got the following error:
Expected behavior Import native nodejs modules correctly