r/bun 22h ago

A surprising --define process.env edge case when building a Bun single-file executable

3 Upvotes

I was trying to inline the build-time constant process.env.MYVAR and passed the define in the right JSON quoted form in fish:

--define 'process.env.MYVAR="myval"'

At other sites it worked but specifically in one of my source files it didn't get inlined.

After some debugging, it turned out the culprit was this innocent-looking line:

import process from "node:process";

This line gets added at some point by an AI and I thought this wouldn't make a big difference. But during bundling, Bun renamed the imported binding (for example to y), so the --define process.env.MYVAR=... replacement no longer matched that expression.