Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(deploy): aws-lambda serve #882

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Conversation

dai-shi
Copy link
Owner

@dai-shi dai-shi commented Sep 15, 2024

Copy link

vercel bot commented Sep 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
waku ✅ Ready (Inspect) Visit Preview Sep 19, 2024 3:48am

Copy link

codesandbox-ci bot commented Sep 15, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@dai-shi dai-shi changed the title refactor(build): aws-lambda serve refactor(deploy): aws-lambda serve Sep 15, 2024
@dai-shi
Copy link
Owner Author

dai-shi commented Sep 15, 2024

@aheissenberger Can you test this and see if it works?

@dai-shi dai-shi mentioned this pull request Sep 16, 2024
76 tasks
@rmarscher
Copy link
Contributor

I have been having trouble with the hono import in the built serve-aws-lambda.js file. It looks like it is not building hono/context into the bundle? Here is a section of the built serve-aws-lambda.js file:

const importHono = () => import("./assets/index-BxM3V2xC.js");
const importHonoContextStorage = () => import("hono/context-storage");
const importHonoNodeServerServeStatic = () => import("./assets/serve-static-CLws5J7J.js");
const importHonoAwsLambda = () => import("./assets/index-DM8TMISb.js");
const { Hono } = await importHono();
const { contextStorage } = await importHonoContextStorage();
const { serveStatic } = await importHonoNodeServerServeStatic();
const { handle } = await importHonoAwsLambda();

And then I get a runtime error on AWS when it tries to serve a page:
Cannot find package 'hono' imported from /var/task/serve-aws-lambda.js

I'm not sure if this is caused by the way I am trying to build this branch and copy to my AWS project dependencies. I have installed hono 4.6.1 in my AWS project.

@rmarscher
Copy link
Contributor

I was able to get it working by commenting out the hono context storage from the serve js content. So that seems to be the only issue. I don't understand how hono/aws-lambda is built correctly but hono/context-storage is not.

@rmarscher
Copy link
Contributor

@rmarscher
Copy link
Contributor

It works for me if I remove external: ['hono/context-storage'] from the vite config for buildServerBundle and use import { importHonoContextStorage } from "waku/unstable_hono"; in a server component.

import { importHonoContextStorage } from "waku/unstable_hono";

const getData = async () => {
  const { getContext } = await importHonoContextStorage();
  const c = getContext();
  const acceptHeader = c.req.header("Accept");
  return { acceptHeader };
}

I had to leave hono/context-storage as external in the dev-server-impl.ts though. I tried updating the runner in cli.ts to import from unstable_hono:

  const contextStorage = (await importHonoContextStorage()).contextStorage;
  app.use(contextStorage());

But that results in Context is not available error. Leaving cli.ts as is works in dev mode while still using importHonoContextStorage in the server component.

I don't personally have a use case for waku start but I have a feeling that might have issues because the hono context in the runner will be different from the one in the build. Maybe the cli could be changed to invoke runners that are part of the server build instead of having a separate runner that imports entries directly.

@rmarscher
Copy link
Contributor

I made a related documentation change in #897

@dai-shi
Copy link
Owner Author

dai-shi commented Sep 24, 2024

@rmarscher Thanks for investigating this.

Oh right... probably this... 58f7ded#diff-275ea9f25448c4618b0f5d5e886b0f4072dad0167fc254e3804e46be65ec2096R249

If that's the problem, why does cloudflare version work?
Can you confirm if the generated file has const importHonoContextStorage = () => import("hono/context-storage"); as well?

@dai-shi
Copy link
Owner Author

dai-shi commented Sep 24, 2024

And then I get a runtime error on AWS when it tries to serve a page:
Cannot find package 'hono' imported from /var/task/serve-aws-lambda.js

Does it work if you install hono manually for your app?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants