Level up your business security with free, on-demand training and certification. Explore 1Password Academy today →
Forum Discussion
cellulosa
1 month agoNew Contributor
Bun cannot read 1Password-mounted .env files directly
Hi everyone,
I’m experimenting with 1Password Local Environment Files for local development, but I ran into an issue when using Bun. Even though I can cat .env and see the correct contents, running:
bun --print process.envreturns nothing — Bun does not pick up any of the variables. After some testing, I found that copying the content into a normal file makes it work:
cp .env .env.development
bun --print process.envThe problem seems to be that Bun cannot reliably read virtual/mounted files (pipes/FUSE mounts). Workarounds that work:
- Use dotenv/x and use `dotenvx run -- bun run ...`
- Use `op run --environment -- bun run ...`
Since https://bun.com/docs/runtime/environment-variables, it should just work with the mounted file, whereas these approaches result in adding extra commands or wrappers all around the monorepo.
It would be great if 1Password could provide guidance on using Bun (or other tools that expect standard filesystem .env files) with mounted local env files.
Has anyone else run into this with Bun or similar tools?
Thanks!
6 Replies
- theoOccasional Contributor
You can probably work around this using varlock (https://varlock.dev)
There is a 1Password plugin to load data from either specific items or environments, and you can wire up your bun app to load your config without a mounted .env file.
- cellulosaNew Contributor
well if I have to run
varlock run --I might run directly
op run --- theoOccasional Contributor
There are a bunch of drop in integrations so in many cases you dont run it that way. Also op run doesnt work with environments. Tons of other features as well, its a full toolkit to deal with config. Loading from 1pass is just one small part of it. But I thought I'd mention because it solves your specific problem of loading environments secrets into a bun app.
- emilysmith
1Password Team
Hey Cellulosa! My apologies for the delayed response here! Thanks for asking - I'll check in with the team to see if they have any suggestions for using our new Environments feature with mounted local .env files and report back with what I learn.