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

env method doesn't work on Cloudflare Pages #3158

Closed
imadoki opened this issue Jul 18, 2024 · 8 comments · Fixed by #3171
Closed

env method doesn't work on Cloudflare Pages #3158

imadoki opened this issue Jul 18, 2024 · 8 comments · Fixed by #3171
Labels

Comments

@imadoki
Copy link

imadoki commented Jul 18, 2024

What version of Hono are you using?

4.5.0

What runtime/platform is your app running on?

Cloudflare Pages

What steps can reproduce the bug?

// src/index.tsx
import { Hono } from "hono";
import { env, getRuntimeKey } from "hono/adapter";
import { renderer } from "./renderer";

const app = new Hono();
app.use(renderer);

type Env = {
  MESSAGE: string;
};

app.get("/", (c) => {
  const { MESSAGE } = env<Env>(c);
  console.log(`MESSAGE: ${MESSAGE}`);
  console.log(`debug MESSAGE: ${c.env.MESSAGE}`);
  console.log(getRuntimeKey());
  return c.json({ message: MESSAGE });
});

vite.config.ts

// vite.config.ts
import build from "@hono/vite-cloudflare-pages";
import devServer from "@hono/vite-dev-server";
import adapter from "@hono/vite-dev-server/cloudflare";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [
    build(),
    devServer({
      adapter,
      entry: "src/index.tsx",
    }),
  ],
});

What is the expected behavior?

Messages set by wrangler pages secret put MESSAGE are displayed.

What do you see instead?

MESSAGES is undefined

Additional information

The log returns the following output.

  (log) MESSAGE: undefined
  (log) debug MESSAGE: foo
  (log) other
@imadoki imadoki added the triage label Jul 18, 2024
@yusukebe
Copy link
Member

Hi @imadoki

This may be a @hono/vite-dev-server matter instead of hono's. I think this issue was fixed in the last version of it, @hono/vite-dev-server@0.13.1. Have you tried it?

@imadoki
Copy link
Author

imadoki commented Jul 19, 2024

Thanks for the reply.

I use @hono/vite-dev-server@0.13.1.

@yusukebe
Copy link
Member

@imadoki

The problem is that the value returned from getRuntimeKey() is other instead of workerd. I can't reproduce it in my env; it logs workerd correctly. Could you provide a minimal project to reproduce it?

@imadoki
Copy link
Author

imadoki commented Jul 20, 2024

I created a minimal project here.

I think I can reproduce the error with the following steps:

  1. clone this repository
  2. pnpm install and pnpm run deploy (create Cloudflare Pages Project)
  3. pnpm wrangler pages secret put MESSAGE
  4. pnpm run deploy

This problem is happening when deploying on Cloudflare Pages, not in the local development environment.

@yusukebe
Copy link
Member

@imadoki

Thank you very much! This might be fixed by #3171. We'll release a new version that includes that fix later.

@yusukebe yusukebe reopened this Jul 21, 2024
@yusukebe
Copy link
Member

Hi @imadoki

Your issue will be fixed with #3171, but if you set the compatibility_date property, it will be fixed without updating the hono.

compatibility_date = "2024-07-20"

Can you try it? If it is solved, change #3171 may not be needed.

@imadoki
Copy link
Author

imadoki commented Jul 21, 2024

I can confirm that using compatibility_date will work around the problem!

Thanks all for the lighting fast response!

@yusukebe
Copy link
Member

@imadoki

Thank you for confirming it. I'll close this issue.

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

Successfully merging a pull request may close this issue.

2 participants