fastify / aws-lambda-fastify

Insipired by aws-serverless-express to work with Fastify with inject functionality.
MIT License
512 stars 32 forks source link

TypeScript and ESM: This expression is not callable. Type ... has no call signatures #144

Closed YannDanthu closed 1 year ago

YannDanthu commented 1 year ago

Prerequisites

Fastify version

3.1.3

Plugin version

No response

Node.js version

18

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.5

Description

Hi,

I have a TS project in ESM mode (type:module) and getting a not callable error on awsLambdaFastiify.

package.json

{
  "dependencies": {
    "@fastify/aws-lambda": "^3.1.3",
    "fastify": "^4.5.3"
  },
  "devDependencies": {
    "@types/aws-lambda": "^8.10.95",
    "@types/got": "^9.6.12",
    "@types/node": "^17.0.22",
    "ts-node": "^10.9.1",
    "typescript": "^4.6.2"
  },
  "type": "module"
}

tsconfig.json

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "target": "ESNext",
  },
  "ts-node": {
    "esm": true
  }
}

lambda-fastify.ts

import awsLambdaFastify from '@fastify/aws-lambda'
import app from './app.js'

export const handler = awsLambdaFastify(app)

Will throw a This expression is not callable. error

Changing the import statement like this has no impact

import * as awsLambdaFastify from '@fastify/aws-lambda';

I have noticed that the node_modules/@fastify/aws-lambda/index.d.ts file does not contain the export = awsLambdaFastify at the end which prevents the import to work properly in ESM I suppose (adding it back make it works). I noticed the same in the releases package source code zip file of previous versions as well.

Steps to Reproduce

On top of elements from the description, here is the app.ts file.

app.ts

import {fastify} from 'fastify'

const app = fastify()
app.get('/', (request, reply) => reply.send({ hello: 'world' }))

export default app

error is highlighted by the IDE it lambda-fastify.ts file as well as running

npx tsc

Expected Behavior

Expect the import awsLambdaFastify to be callable and return a PromiseHandler.

Thank you for the help on this.

Uzlopak commented 1 year ago

We need a release.

@adrai @mcollina

adrai commented 1 year ago

@Uzlopak because of the TS changes? Which version bump? major, minor, patch?

Uzlopak commented 1 year ago

Yes the TS Changes. I would say minor.

adrai commented 1 year ago

v3.2.0 is released

Uzlopak commented 1 year ago

@YannDanthu

Can you please test if with 3.2.0 your issue is fixed or not?

YannDanthu commented 1 year ago

Problem solved 👏

Thank you very much ! 🥇