Comments (4)
Summary
It looks like this is a regression in Middy 5, maybe. I still use Middy 4 due to that being the latest version supported by AWS Powertools, so I never noticed this problem. Also, the example in the docs has a minor bug where it references event.path
instead of req.path
.
Reproduction Steps
This differs a bit from the example shared in the issue description because the tsconfig there gave me ESM problems that weren't really related to the problem at hand. Maybe I needed to set module: true
in package.json or something, but I just can't be bothered to deal with any more ESM related problems in my life, so here's a simplified reproduction that sidesteps that:
Create files
package.json:
{
"name": "middy-example",
"version": "1.0.0",
"dependencies": {
"@middy/core": "^5.4.3",
"@middy/secrets-manager": "^5.4.3",
"@types/aws-lambda": "^8.10.141",
"@types/node": "^20.14.10",
"typescript": "^5.5.3"
}
}
tsconfig.json:
{
"compilerOptions": {
"target": "es2022",
"module": "commonjs",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true
}
}
index.ts:
import middy from '@middy/core'
import secretsManager from '@middy/secrets-manager'
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'
export const handler = middy<APIGatewayProxyEvent, APIGatewayProxyResult>()
.use(
secretsManager({
fetchData: {
apiToken: 'dev/api_token',
},
awsClientOptions: {
region: 'us-east-1',
},
setToContext: true,
})
)
.handler(async (req, context) => {
// The context type gets augmented here by the secretsManager middleware.
// This is just an example, obviously don't ever log your secret in real life!
console.log(context.apiToken)
return {
statusCode: 200,
body: JSON.stringify({
message: `Hello from ${req.path}`,
req,
}),
}
})
Run tsc to check types
Command:
npm install && npx tsc --noEmit --pretty
index.ts:17:19 - error TS7006: Parameter 'req' implicitly has an 'any' type.
17 .handler(async (req, context) => {
~~~
index.ts:17:24 - error TS7006: Parameter 'context' implicitly has an 'any' type.
17 .handler(async (req, context) => {
~~~~~~~
Found 2 errors in the same file, starting at: index.ts:17
Workaround
Downgrading to Middy 4 makes it work:
{
"name": "middy-example",
"version": "1.0.0",
"dependencies": {
"@middy/core": "^4.7.0",
"@middy/secrets-manager": "^4.7.0",
"@types/aws-lambda": "^8.10.141",
"@types/node": "^20.14.10",
"typescript": "^5.5.3"
}
}
from middy.
Thanks!
I created a separate PR to fix the docs.
from middy.
merged, and docs rebuilding now
from middy.
@willfarrell The PR I opened only addresses the documentation. However, this regression issue remains unresolved.
from middy.
Related Issues (20)
- error-logger: Call implementation function with await prefix HOT 1
- ApproximateReceiveCount limit on SqsPartialBatch HOT 5
- Conditional middleware HOT 3
- (Aware of other issues) No "exports" main defined in /var/task/node_modules/@middy/core/package.json HOT 7
- input-output-logger: replacer function is not called HOT 3
- Error: No "exports" main defined in /path/to/the/repo/node_modules/@middy/core/package.json HOT 1
- @middy/http-content-encoding not awaiting onError HOT 1
- Consistent multipart body parser response format HOT 1
- ā No "exports" main defined in ***i/node_modules/@middy/core/package.json
- `ws-response`: Invalid URL format gave to `ApiGatewayManagementApiClient` HOT 4
- `ws-response`: Invalid `request.response` given to API Gateway HOT 1
- Latest version of @middy/core breaks types in the handler function HOT 9
- TypeScript unable to infer types HOT 3
- Handler return is not type-checked. HOT 3
- Lack of support for hyphenated path parameters in @middy/http-router HOT 6
- Incompatibility of `@middy/core` with Node.js v20.16.0 in Serverless Framework Project HOT 1
- Bug Report: Incompatibility of `@middy/core` with Node.js v20.16.0 in Serverless Framework Project HOT 1
- Support for AsyncLocalStorage store.run HOT 4
- Support CommonJS (again) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from middy.