shiftcode / dynamo-easy

DynamoDB client for NodeJS and browser with a fluent api to build requests. We take care of the type mapping between JS and DynamoDB, customizable trough typescript decorators.
https://shiftcode.github.io/dynamo-easy/
MIT License
204 stars 27 forks source link

How to use with @aws-cdk/aws-lambda-nodejs #363

Closed matthias-pichler-warrify closed 2 years ago

matthias-pichler-warrify commented 2 years ago

Describe the bug

When I try to deploy my TypeScript Lambdas using the @aws-cdk/aws-lambda-nodejs the invocations fail with:

2021-09-21T16:19:24.193Z    undefined   ERROR   Uncaught Exception  {
    "errorType": "Error",
    "errorMessage": "make sure you have enabled the typescript compiler options which enable us to work with decorators (see doc)",
    "stack": [
        "Error: make sure you have enabled the typescript compiler options which enable us to work with decorators (see doc)",
        "    at createNewProperty (/var/task/index.js:33673:15)",
        "    at Object.initOrUpdateProperty (/var/task/index.js:33665:20)",
        "    at /var/task/index.js:33947:46",
        "    at __decorateClass (/var/task/index.js:66:24)",
        "    at model/api-key.ts (/var/task/index.js:38123:5)",
        "    at __init (/var/task/index.js:41:50)",
        "    at Object.<anonymous> (/var/task/index.js:38166:18)",
        "    at Module._compile (internal/modules/cjs/loader.js:1072:14)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)",
        "    at Module.load (internal/modules/cjs/loader.js:937:32)"
    ]
}

Since @aws-cdk/aws-lambda-nodejs uses esbuild which doesn't support emitDecoratorMetadata this isn't surprising.

However for some reason transpiling with tsc first doesn't solve the issue either.

A PR is currently open in the @aws-cdk repo to do exactly this to work around this. I tried their approach without success. Will this PR make dynamo-easy work with @aws-cdk/aws-lambda-nodejs?

To Reproduce Steps to reproduce the behavior:

  1. Write a function using decorators from dynamo-easy
  2. Deploy them using @aws-cdk/aws-lambda-nodejs
  3. Invoke them
  4. See error

Expected behavior

Additional context

hassanazharkhan commented 2 years ago

@matthias-pichler-warrify Transpiling first and pass the output to esbuild is indeed working for me, I'm not sure why this isn't working for you. Could you please share a minmal repo of the bug you're facing. I would really like to take a look.

Please have a look on this Issue and this Repo

michaelwittwer commented 2 years ago

closing this in favour of #374 holding relevant topics to be updated in the docs, serving as a knowledge base for now and also describing the strategy of the technical solution of the documentation part, envision it to be closer to the source code of the project