fix(windows): isMainModule CJS branch fails on Bun — add CLAUDE_MEM_MANAGED fallback
On Bun/Windows, `require.main !== module` in CJS mode causes the worker to exit silently with code 0. The wrapper already sets CLAUDE_MEM_MANAGED=true when spawning the inner worker, so checking this env var is a safe fallback that doesn't affect standalone execution. Ref #1450 (incomplete fix in PR #1518 — ESM path fixed but CJS branch not). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1307,8 +1307,10 @@ async function main() {
|
||||
}
|
||||
|
||||
// Check if running as main module in both ESM and CommonJS
|
||||
// The CLAUDE_MEM_MANAGED check handles Bun on Windows where require.main !== module
|
||||
// in CJS mode despite being the entry point (see #1450)
|
||||
const isMainModule = typeof require !== 'undefined' && typeof module !== 'undefined'
|
||||
? require.main === module || !module.parent
|
||||
? require.main === module || !module.parent || process.env.CLAUDE_MEM_MANAGED === 'true'
|
||||
: import.meta.url === `file://${process.argv[1]}`
|
||||
|| process.argv[1]?.endsWith('worker-service')
|
||||
|| process.argv[1]?.endsWith('worker-service.cjs')
|
||||
|
||||
Reference in New Issue
Block a user