Compare commits

...

1 Commits

Author SHA1 Message Date
Claude Bot
f7a3eddc42 fix(bundler): prevent NODE_ENV inlining when env is "disable" via JS API
When using `Bun.build({ env: "disable" })`, `process.env.NODE_ENV` was
still being inlined to its current value (e.g. "development"). The CLI
`--env=disable` worked correctly. The issue was that the JS API mapped
"disable" to `.disable` enum value, but the NODE_ENV inlining guard in
`definesFromTransformOptions` only checked for `.load_all_without_inlining`.

Fixes #19508

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-19 09:29:04 +00:00
2 changed files with 18 additions and 1 deletions

View File

@@ -1483,7 +1483,7 @@ pub fn definesFromTransformOptions(
);
}
if (behavior != .load_all_without_inlining) {
if (behavior != .load_all_without_inlining and behavior != .disable) {
const quoted_node_env: string = brk: {
if (NODE_ENV) |node_env| {
if (node_env.len > 0) {

View File

@@ -65,6 +65,23 @@ for (let backend of ["api", "cli"] as const) {
},
});
// #19508 - env: "disable" should also prevent NODE_ENV from being inlined
itBundled("env/disable-node-env", {
backend: backend,
dotenv: "disable",
files: {
"/a.js": `console.log(process.env.NODE_ENV);`,
},
onAfterBundle(api) {
const content = api.readFile("/out.js");
if (!content.includes("process.env.NODE_ENV")) {
throw new Error(
"process.env.NODE_ENV was inlined but should have been preserved with env: 'disable'. Output:\n" + content,
);
}
},
});
// TODO: make this work as expected with process.env isntead of relying on the initial env vars.
// Test pattern matching - only vars with prefix are inlined
if (backend === "cli")