You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
export MYOTHERVAR=hmmm
bun build --outdir bundled test.ts --target=bun
What is the expected behavior?
Expect to see directly specified environment variables used when supplied so that I can use environment variables for configuration/externalization of secrets. Running typescript directly with bun works:
MYVAR=hello MYOTHERVAR=world bun test.ts
hello
world
What do you see instead?
Values from .envand the environment are inlined into the bundle/compiled executable when --target=bun used. Referenced environment variables that had no value during build work as expected:
MYVAR=hello MYOTHERVAR=world bun ./bundled/test.js
gotcha
hmmm
Additional information
Unwanted inlining will embed secrets into bundles/executables. I already did this without realising:
The behaviour of target is documented at https://bun.sh/docs/bundler#target but does not mention anything about inlining environment variables and .env files
I guess the workaround would be to run bun compile in a clean environment and move any .env files out of the way first
The text was updated successfully, but these errors were encountered:
What version of Bun is running?
1.1.8+89d25807f
What platform is your computer?
Linux 6.1.0-17-amd64 x86_64 unknown
What steps can reproduce the bug?
bun build --target=bun
inlines the value of environment variables set in the environment and.env
, eg:.env
test.ts
bundle
export MYOTHERVAR=hmmm bun build --outdir bundled test.ts --target=bun
What is the expected behavior?
Expect to see directly specified environment variables used when supplied so that I can use environment variables for configuration/externalization of secrets. Running typescript directly with
bun
works:What do you see instead?
Values from
.env
and the environment are inlined into the bundle/compiled executable when--target=bun
used. Referenced environment variables that had no value during build work as expected:Additional information
Unwanted inlining will embed secrets into bundles/executables. I already did this without realising:
The behaviour of
target
is documented at https://bun.sh/docs/bundler#target but does not mention anything about inlining environment variables and.env
filesI guess the workaround would be to run
bun compile
in a clean environment and move any.env
files out of the way firstThe text was updated successfully, but these errors were encountered: