serverless-express
serverless-express copied to clipboard
Typescript: Cannot find module 'aws-lambda' or its corresponding type declarations.
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
Sorry about that. Could you send a PR?
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?
@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... 🤔
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.
I had this issue too, I can see a few solutions:
- You could just add it as a
peerDependency
. Consumers can choose to put it into theirdevDependencies
that way. - Just put it into the module tree (in dependencies). It's not a perfect solution.
- 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.
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.