Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Typescript] Runtime type error #810

Closed
kazkansouh opened this issue Feb 20, 2022 · 2 comments
Closed

[Typescript] Runtime type error #810

kazkansouh opened this issue Feb 20, 2022 · 2 comments

Comments

@kazkansouh
Copy link

Describe the bug

Using Serverless framework with serverless-plugin-typescript. At runtime, the following type error is produced:

(0 , core_1.default) is not a function

To Reproduce
How to reproduce the behaviour:

See https://github.com/kazkansouh/middy-bug for a self contained example.

  1. Create serverless framework project with serverless-plugin-typescript.
  2. Code for handler
    import middy from '@middy/core'
    import { APIGatewayProxyHandler } from 'aws-lambda'
    const gatewayHandler: APIGatewayProxyHandler = async (event, context) => {
      const response = { result: 'success', message: 'payment processed correctly' }
      return { statusCode: 200, body: JSON.stringify(response) }
    }
    export const handler = middy(gatewayHandler)
  3. Deploy code, and then access endpoint.
  4. Thrown error (from AWS cloudwatch logs)
    2022-02-20 13:37:45.787 ERROR   Uncaught Exception      {"errorType":"TypeError","errorMessage":"(0 , core_1.default) is not a function","stack":["TypeError: (0 , core_1.default) is not a function","    at Object.<anonymous> (/var/task/src/fulfillment.js:193:38)","    at Module._compile (internal/modules/cjs/loader.js:1085:14)","    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)","    at Module.load (internal/modules/cjs/loader.js:950:32)","    at Function.Module._load (internal/modules/cjs/loader.js:790:12)","    at Module.require (internal/modules/cjs/loader.js:974:19)","    at require (internal/modules/cjs/helpers.js:93:18)","    at _tryRequireFile (/var/runtime/UserFunction.js:63:32)","    at _tryRequire (/var/runtime/UserFunction.js:151:20)","    at _loadUserApp (/var/runtime/UserFunction.js:197:12)"]}
    

Expected behaviour

Does not raise type error.

Environment (please complete the following information):

$ npm ls
[email protected] /dev/shm/bug/middy-bug
├── @middy/[email protected]
├── @types/[email protected]
├── [email protected]
├── [email protected]
└── [email protected]
@willfarrell
Copy link
Member

This might be resolved by middy hopefully to moving to esm for v3. But, there are still some unknowns from AWS on what they are doing. aws-powertools/powertools-lambda-typescript#465 might have a workaround for you.

#584

@kazkansouh
Copy link
Author

@willfarrell Thankyou for the help. Yep, you are correct. adding esModuleInterop to tsconfig.json works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants