-
Notifications
You must be signed in to change notification settings - Fork 5
Closed
Labels
@arkenv/bun-pluginIssues or Pull Requests involving the Bun plugin for ArkEnvIssues or Pull Requests involving the Bun plugin for ArkEnvenhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Milestone
Description
When using arkenv in a Bun + React project, process.env is not defined in the frontend runtime. Bun only exposes environment variables that are explicitly prefixed (default: BUN_PUBLIC_*) and accessing process.env directly throws a runtime error.
Additionally, during the build step, Bun's bundler defaults to browser builds, which causes import errors such as:
import { styleText } from "util";
^
error: Browser polyfill for module "node:util" doesn't have a matching export named "styleText"Steps to Reproduce:
- Create a clean React template with bun init.
- Install arkenv.
- Import and call createEnv.
- Run bun serve → runtime error: process is not defined.
- Run bun build → bundler error on styleText.
Expected behavior:
arkenv should support Bun's process.env model, allowing retrieval of all variables with a given prefix (e.g., BUN_PUBLIC_*).
Workaround:
Manually construct the env object and pass only the prefixed vars to the schema:
import { type } from "arktype"
const envType = type({ MY_VAR: "string" })
const env = envType.assert({ MY_VAR: process.env.BUN_PUBLIC_MY_VAR })
export default envRelated:
- Bun issue: ENV variables in a frontend dev server oven-sh/bun#19313
- Support runtime access in Vite for prefixed vars (e.g.
VITE_*) #288 (Vite frontendimport.meta.envprefixing)
Action Items:
- Add support for collecting env vars by a configurable prefix (default:
BUN_PUBLIC_*). - Ensure builds targeting browser/bun don't attempt to import Node-only utilities like
util.styleText.
Reactions are currently unavailable
Metadata
Metadata
Labels
@arkenv/bun-pluginIssues or Pull Requests involving the Bun plugin for ArkEnvIssues or Pull Requests involving the Bun plugin for ArkEnvenhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed