aws-cdk: (aws-lambda-nodejs): esbuild does not support emitting typescript decorator metadata
Somewhere in the recent version of ‘aws-lambda-nodejs’ module, the default bundler for aws-lambda-nodejs was changed from ‘parcel’ to ‘esbuild’. Bundling performance has improved greatly but all my handlers are broken now (all the ones that were relying on ts metadata reflaction).
This has to do with how esbuild transpiles typescript code, as stated here by the author of esbuild, emitDecoratorMetadata is not and will not be supported by esbuild, but this would break all other libraries that rely on the availability of run time metadata.
like: TypeORM, TypeDORM, Nestjs.
I think aws-lambda-nodejs should auto handle pre-transpiling files with decorators using tsc and later continue with esbuild. (Similar suggested by the author of esbuild too.)
Reproduction Steps
Trying to bundle a simple nodejs project using Reflect metadata api should demonstrate the problem.
What did you expect to happen?
when bundling code with aws-lambda-nodejs decorator metadata should be reflected properly.
What actually happened?
Decorator metadata is not reflected in the fine js bundle.
If this is something aws-lambda-nodejs should handle, I can do a PR.
Environment
- **CDK CLI Version :1.91
- **Framework Version:1.91
- **Node.js Version:14.15
- **OS :linux
- **Language (Version):TypeScript (3.9.9)
This is 🐛 Bug Report
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 13
- Comments: 19 (10 by maintainers)
Commits related to this issue
- feat(lambda-nodejs): typescript emitDecoratorMetadata support (#16543) closes [#13767](https://github.com/aws/aws-cdk/issues/13767) ---- *By submitting this pull request, I confirm that my cont... — committed to aws/aws-cdk by hassanazharkhan 3 years ago
- feat(lambda-nodejs): typescript emitDecoratorMetadata support (#16543) closes [#13767](https://github.com/aws/aws-cdk/issues/13767) ---- *By submitting this pull request, I confirm that my cont... — committed to TikiTDO/aws-cdk by hassanazharkhan 3 years ago
@modul You are not missing anything,there seems to be bug with preCompiled flag if you try to bundle using docker it will probably work but not sure however I will try to PR the fix ASAP!
@whimzyLive any update over this ?
+1 for @whimzyLive submitting a PR 😃
@deldrid1 Sorry, wasn’t able to get this fix in, but if you want to pick it up, basically everything that needs to get fixed is in the patch that I had pasted above except one change where you will have to take into consideration that a project might be using multiple extended tsconfig.json, in that case, you would want to start by the very first tsconfig.json in the tree and continue merging all configs until you are at the base config.
Otherwise, I will get it done at some point this week. 🤞
@whimzyLive Have you been able to create a PR for this?
@whimzyLive, if I understand correctly, the feature request here is to add a feature to lambda-nodejs which uses tsc for transpiling .ts to .js before bundling?