serverless-express icon indicating copy to clipboard operation
serverless-express copied to clipboard

Typescript: Cannot find module 'aws-lambda' or its corresponding type declarations.

Open shawnsparks-work opened this issue 4 years ago • 6 comments

I get this error from src/configure.d.ts when using typescript:

node_modules/@vendia/serverless-express/src/configure.d.ts:2:25 - error TS2307: Cannot find module 'aws-lambda' or its corresponding type declarations.

I don't see aws-lambda in the package.json at all. I was able to get it to build by adding @types/aws-lambda as a devDependency.

@vendia/serverless-express: 4.3.2 typescript: 4.1.5

shawnsparks-work avatar Feb 19 '21 14:02 shawnsparks-work

Sorry about that. Could you send a PR?

brettstack avatar Feb 19 '21 20:02 brettstack

After thinking about this more, I'm not sure how this should be addressed. It seems odd to define @types/aws-lambda as a dependency for everybody to pull down if not everyone is using typescript. Thooughts?

shawnsparks-work avatar Mar 03 '21 03:03 shawnsparks-work

@types/aws-lambda is currently listed in devDependencies in this package.

I'm not sure what the correct way to solve this is though since as you said we don't want to stick it in dependencies and force JS users to install types. Surely this problem has been solved before... 🤔

brettstack avatar Mar 03 '21 22:03 brettstack

One option would be to make typescript users install it themselves and make a note to do so. I just had this issue myself. Installing types fixed the problem.

alko89 avatar Apr 08 '21 15:04 alko89

I had this issue too, I can see a few solutions:

  1. You could just add it as a peerDependency. Consumers can choose to put it into their devDependencies that way.
  2. Just put it into the module tree (in dependencies). It's not a perfect solution.
  3. You don't return aws-lambda types, instead you return your own declared type. I can't speculate how many users need access to the type is unknown, but they can always overwrite it in consumer

I'll put a proposal forward of what I think works, please provide feedback.

eastwood avatar Apr 21 '21 06:04 eastwood

just bumping this as it's still an issue which I'm facing. Adding the dependencies into my project's module tree did give an ad-hoc fix to the error.

chav-aniket avatar Jul 02 '22 17:07 chav-aniket