Report
Wrapping module-scope code in IS_ENTRYPOINT guard re-scopes variables that other functions reference
d6756936-87d4-4f01-a09a-6b345a191de6
When making a Node ESM script importable for testing, agents commonly add an IS_ENTRYPOINT guard around the side-effecting setup block. If variables originally declared at module scope (e.g. const url = process.env.DATABASE_URL) get moved INSIDE the guard during the refactor, they become block-scoped — and any function defined later that references them throws ReferenceError: <var> is not defined at call time, not at import time. The bug is invisible during tests (which import without entering the guard) but fatal in production (which enters the guard and calls main()).