middyjs / middy

🛵 The stylish Node.js middleware engine for AWS Lambda 🛵

Home Page:https://middy.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not able to invoke the http-router routes from post-man using serverless-offiline

SameerSiddiqui opened this issue · comments

  "compilerOptions": {
      "experimentalDecorators": true,
      "emitDecoratorMetadata": true,
      "noImplicitAny": true,
      "target": "ES2020",
      "module": "commonjs",
      "declaration": true,
      "declarationMap": true,
      "outDir": "lib",
      "removeComments": false,
      "strict": true,
      "inlineSourceMap": true,
      "moduleResolution": "node",
      "resolveJsonModule": true,
      "esModuleInterop": true,
      "pretty": true,
      "baseUrl": "src/",
      "rootDirs": [ "src/" ]
  },
  "include": [ "src/**/*"],
  "exclude": [ "./node_modules"],
  "watchOptions": {
      "watchFile": "useFsEvents",
      "watchDirectory": "useFsEvents",
      "fallbackPolling": "dynamicPriority"
  },
  "lib": [ "es2020" ],
  "types": [
      "jest",
      "node"
  ]
}

```serverless
functions:
  handler:
    role: LambdaExecutionRole
    handler: dist/index.handler
    events:
      - http:
          path: /user/status
          method: any
          cors: true

index.ts


loggerService.info('Lambda Initiated');
const logger = (message: any) => loggerService.error(message);
export const handler = middy()
  .use(httpHeaderNormalizer())
  .use(httpJsonBodyParser())
  .use(httpSecurityHeadersMiddleware())
  .use(httpErrorHandler({ logger }))
  .handler(httpRouterHandler(routes));```

node v18.17.0

npm run build // compiles the ts 
serverless-offline 

go to Postman to invoke the routes http://localhost:3000/devint/user/status

ANY /devint/user/status (λ: handler)
✖ Unhandled exception in handler 'handler'.
✖ Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in */node_modules/@middy/core/package.json

Looks like a build issue.

"module": "commonjs"

If you require commonjs support you'll need to use v4.x as it's not support v5.x

Thank you that worked. what about http-router which version is compatible ?

basically, am i able to use different middlewares and http-router with commonjs ?

what about http-router which version is compatible ?

both

am i able to use different middlewares and http-router with commonjs ?

Yes, assuming they all support commonjs