Skip to content

Built applications can't find any environment variables #307

@jkupcho

Description

@jkupcho

I'm trying to figure out a way to use environment variables in a bun honox application.

This issue #79 talks about how the vite serve could inject environment variables into the application via vite config and dotenv. This works in the development server, but if I build the application and try to access the environment variables, nothing I've tried seems to work.

Bun should automatically load .env files at startup, but I have yet to get a built honox application to recognize any sort of environment variable.

I've provided a sample application here:
https://github.com/jkupcho/honox-env-issue

If you pull the repository, running bun dev you'll see the environment variable outputting correctly, however, if you run bun run build then bun dist/index.js nothing is displayed for the environment variable. I've even tried setting it before I run the app with:
COOL_VAR=another_something && bun dist/index.js

This also does not seem to work, undefined is logged in the console. Note, export COOL_VAR=another_something also does not seem to work. It seems like environment variables are completely lost on the running application.

Also of note, this does work with honojs, so maybe I'm missing something with how the honox applications are working.

Any pointers would be greatly appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions