vite-plugins icon indicating copy to clipboard operation
vite-plugins copied to clipboard

bug?: `import.meta.env.VAR` does not work

Open vladimirleonidovich opened this issue 7 months ago • 5 comments

What version of HonoX are you using?

0.1.40

What steps can reproduce the bug?

Create .env.local with the following contents:

DB_PASSWORD="secret"

Create simple console.log in / route like this:

console.log(import.meta.env.DB_PASSWORD)

What is the expected behavior?

secret gets printed.

What do you see instead?

undefined gets printed.

Additional information

VITE_ prefixed environment variables are created to be exposed in client code so prefixing DB_PASSWORD with VITE_ would be a bad idea but in this case I have to. So I guess it’s bug?

https://vite.dev/guide/env-and-mode.html#env-variables

vladimirleonidovich avatar Jun 09 '25 01:06 vladimirleonidovich

Hi @vladimirleonidovich

I'll investigate it. Are you using @hono/vite-dev-server with Vite?

yusukebe avatar Jun 12 '25 00:06 yusukebe

@yusukebe hello there! I do, of course.

vladimirleonidovich avatar Jun 12 '25 02:06 vladimirleonidovich

This issue is related to @hono/vite-dev-server. I'll transfer this.

yusukebe avatar Jun 23 '25 00:06 yusukebe

Related to #258

yusukebe avatar Jun 23 '25 00:06 yusukebe

Hi @vladimirleonidovich

VITE_ prefixed environment variables are created to be exposed in client code so prefixing DB_PASSWORD with VITE_ would be a bad idea but in this case I have to.

You are right. And it's not a bug. It's hard to use, but it's expected behavior. For this case, you have to add VITE_ prefix.

yusukebe avatar Jun 23 '25 00:06 yusukebe