-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Description
What version of Bun is running?
1.3.1+89fa0f343
What platform is your computer?
Linux 6.17.5-arch1-1 x86_64 unknown
What steps can reproduce the bug?
Create a HTML template that references a JS file/module with the following content:
// main.js
const works = () => console.log("Works: " + process.env.ACME_PUBLIC_ENV);
const doesnt_work = () => {
const process = {
env: {
PUBLIC_ENV: "123"
}
}
console.log("Works: " + process.env.ACME_PUBLIC_ENV);
};
works();
doesnt_work();Bundle with the following command:
ACME_PUBLIC_ENV="development" bun build main.html --outdir ./dist --env ACME_PUBLIC_*What is the expected behavior?
I'd expect both references to process.env.ACME_PUBLIC_ENV to be replaced with "development"
What do you see instead?
It only replaces the reference to process.env.ACME_PUBLIC_ENV if I didn't define it beforehand, this took a while for me to notice because while giving this feature a try I wanted to keep it safe so though I'd define a default value beforehand so that things wouldn't break if I forgot to specify the env var. Not sure whether this is a bug, can understand the behaviour, but it should probably be noted in the docs or maybe a warning should be emitted. Only later did I discover that me trying to be careful ended up breaking this feature.
Additional information
No response