honojs / hono

Web framework built on Web Standards
https://hono.dev
MIT License
20.05k stars 570 forks source link

CloudFrontResult needs to be exported? #2778

Closed ronster37 closed 4 months ago

ronster37 commented 5 months ago

What version of Hono are you using?

4.3.10

What runtime/platform is your app running on?

Lambda@Edge

What steps can reproduce the bug?

The linter is failing just following the tutorial. It's having an issue with the return type of the handle function (CloudFrontResult).

Screenshot 2024-05-23 at 6 22 16 PM

I think CloudFrontResult may just need to be exported.

What is the expected behavior?

No lint errors from the basic tutorial.

What do you see instead?

Lint error on handle function.

Additional information

No response

fzn0x commented 5 months ago

What is your VSCode TypeScript version?

Or try 5.4.5 and see if the bug still exists

Screenshot 2024-05-25 003251

ronster37 commented 5 months ago

@fzn0x I appreciate the prompt response.

It is 5.4.5 unfortunately.

ronster37 commented 5 months ago

I tried 5.3.3 and 4.9.5 and still seeing the same thing.

If I manually add the export on the CloudFrontResult interface in the node_modules, that seems to resolve the problem though.

yusukebe commented 5 months ago

Hi @ronster37 !

I've tried it in my environment, but it does not reproduce. I can add export for CloudFrontResult, but will it fixed with that change?

diff --git a/src/adapter/lambda-edge/handler.ts b/src/adapter/lambda-edge/handler.ts
index 12e58cc..f7bd52f 100644
--- a/src/adapter/lambda-edge/handler.ts
+++ b/src/adapter/lambda-edge/handler.ts
@@ -85,7 +85,7 @@ export interface Callback {
 }

 // https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-generating-http-responses-in-requests.html#lambda-generating-http-responses-programming-model
-interface CloudFrontResult {
+export interface CloudFrontResult {
   status: string
   statusDescription?: string
   headers?:
ronster37 commented 5 months ago

@yusukebe That's very strange. What version of node are you using? I tried v22 and v18 and still experienced this issue 🤔

yusukebe commented 5 months ago

@ronster37

Hmm..yes, strage. I think this is not a Node.js matter but a TypeScript problem. Can you try to create the project with the following command again?

npm create hono@latest -- --template lambda-edge
ronster37 commented 5 months ago

Yes, that worked. The tsconfig.json file differs greatly from the one generated by following the documentation. Because of this, I was able to locate the issue.

Here is the tsconfig.json generated using cdk init app -l typescript:

  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "lib": [
      "es2020",
      "dom"
    ],
    "declaration": true,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": false,
    "inlineSourceMap": true,
    "inlineSources": true,
    "experimentalDecorators": true,
    "strictPropertyInitialization": false,
    "typeRoots": [
      "./node_modules/@types"
    ]
  },
  "exclude": [
    "node_modules",
    "cdk.out"
  ]
}

Removing (or setting to false) the declaration attribute solves the issue. I added "skipLibChecks" and "skipDefaultLibCheck" but it had no effect.

I think removing it might be ok since I will not be building a library.

yusukebe commented 5 months ago

@ronster37

Thank you for sharing the tsconfig.json! But it is weird. It does not show the error in my environment with your config.

I think removing it might be ok since I will not be building a library.

Yeah. It may be so.

ronster37 commented 4 months ago

I'm going to close this out for now.

For anyone else who encounters this remove "declaration": true fixes this problem.