fix: add direct .node require fallback for Bun compiled binaries#356
fix: add direct .node require fallback for Bun compiled binaries#356
Conversation
NAPI-RS generated index.js uses existsSync() to check for .node files, which can fail inside Bun's virtual filesystem ($bunfs) in compiled binaries. Add loadNativeForPlatform() as a fallback that uses string literal require() paths, ensuring Bun's bundler statically discovers and embeds the .node files during `bun build --compile`. Also add VIBE_DEBUG diagnostic log for copy strategy selection. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Enhance the beta release workflow to run the compiled binary on native targets (non-cross-compilation) with VIBE_DEBUG=1, verifying that the native module actually loads at runtime rather than relying solely on string search. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PR Review: Fix native module loading in Bun compiled binariesSummaryThis PR addresses a critical issue where the native module fails to load inside Bun's compiled binary virtual filesystem ($bunfs) due to NAPI-RS's existsSync() check failing. The solution adds a fallback loading path using string literal require() calls that Bun's bundler can statically analyze. Code Quality & Best PracticesStrengths:
Suggestions:
Potential IssuesCriticalNone identified - the core logic is sound. Minor
Performance ConsiderationsExcellent:
Security ReviewPass - No security concerns identified:
Aligns with project's security checklist (docs/SECURITY_CHECKLIST.md). Test CoverageConcerns:
Recommendation: Add tests in a follow-up PR (non-blocking). Documentation UpdatesStatus: No updates needed Checked:
The PR body clearly explains the issue and solution. License CompatibilityStatus: Pass
CI Workflow EnhancementExcellent addition:
Minor suggestion: Overall AssessmentStatus: Approve with minor suggestions Strengths:
Recommendations for follow-up:
Merge recommendation: LGTM - Ready to merge after addressing test coverage in a follow-up PR (non-blocking). Great work on identifying and fixing this Bun bundler issue! The solution is elegant and maintains backward compatibility while adding the necessary fallback path. |
Summary
loadNativeForPlatform()fallback innative.tsthat directlyrequire()s.nodefiles using string literals, bypassing NAPI-RSindex.js'sexistsSync()check which can fail inside Bun's$bunfsvirtual filesystemVIBE_DEBUGdiagnostic log for copy strategy selection instart.tsContext
In Bun compiled binaries, the NAPI-RS generated
index.jsusesexistsSync(join(__dirname, "*.node"))to check for.nodefiles before loading them. Inside Bun's virtual filesystem ($bunfs),existsSynccan returnfalse, causing the native module load to silently fail and fall back to slowcp -cRinstead of fastclonefile()syscall.The fix adds a second loading path using string literal
require()calls that Bun's bundler can statically analyze and embed duringbun build --compile.Test plan
pnpm run check:allpasses (353 tests, lint, typecheck all green)available: true, supportsDirectory: true)VIBE_DEBUG=1 vibe start <branch>thatCopy strategy: clonefileis reported on macOS🤖 Generated with Claude Code