Skip to content

fix(desktop): include bindings package for better-sqlite3 native module#483

Merged
saddlepaddle merged 7 commits into
mainfrom
fix/sqlite-bindings
Dec 23, 2025
Merged

fix(desktop): include bindings package for better-sqlite3 native module#483
saddlepaddle merged 7 commits into
mainfrom
fix/sqlite-bindings

Conversation

@saddlepaddle
Copy link
Copy Markdown
Collaborator

@saddlepaddle saddlepaddle commented Dec 23, 2025

Summary

  • Fixes crash on startup in production build caused by missing bindings package
  • The better-sqlite3 native module uses bindings to locate its .node file at runtime
  • Added bindings and file-uri-to-path to electron-builder configuration
  • Updated copy-native-modules.ts to handle these dependencies

Test plan

  • Build production release
  • Verify app launches without "Cannot find module 'bindings'" error
  • Verify SQLite database operations work correctly

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Improved native-module packaging and install process for the desktop app, including added support for required native runtimes and build steps to ensure modules are included at release.
  • Bug Fixes
    • Resolved issues with native bindings and path handling to reduce runtime errors and improve stability on desktop installations.

✏️ Tip: You can customize this high-level summary in your review settings.

better-sqlite3 uses the `bindings` npm package to locate its native
.node file at runtime. This package (and its dependency file-uri-to-path)
were not being included in the electron-builder output, causing the app
to crash on startup with "Cannot find module 'bindings'" error.

Changes:
- Add bindings and file-uri-to-path to electron-builder files section
- Add both packages to asarUnpack for proper path resolution
- Update copy-native-modules.ts to also handle these dependencies

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 23, 2025

Warning

Rate limit exceeded

@saddlepaddle has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 4 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 0028a26 and dd4246a.

📒 Files selected for processing (1)
  • apps/desktop/electron-builder.ts

Walkthrough

Adds unpack/copy rules and dependencies for native-related modules in the Electron desktop build and refactors the native-module copy script to distinguish required vs optional native modules and to replace workspace symlinks with real files before packaging.

Changes

Cohort / File(s) Summary
Build configuration
apps/desktop/electron-builder.ts
Adds bindings and file-uri-to-path to asarUnpack and files packaging rules, enables npmRebuild: true, and adds comments about Bun workspace symlink handling.
Package dependencies
apps/desktop/package.json
Adds runtime dependencies: bindings@^1.5.0, file-uri-to-path@^1.0.0, and node-addon-api@^7.1.0.
Native module copy script
apps/desktop/scripts/copy-native-modules.ts
Adds copyModuleIfSymlink() helper, introduces NATIVE_MODULE_DEPS (optional deps) and refactors prepareNativeModules() to copy required and optional native modules with explicit logging and symlink replacement behavior.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ❓ Inconclusive The description covers the main issue, root cause, solution, and test plan. However, it deviates from the required template structure by using a custom Summary/Test Plan format instead of the standard Description/Related Issues/Type of Change/Testing sections. Restructure the description to follow the template: add Related Issues section, clearly mark Type of Change (Bug fix), and organize Testing as a separate section with detailed verification steps.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: including the bindings package for better-sqlite3 native module support in the desktop build, which directly addresses the startup crash issue in production.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

The `bindings` package (used by better-sqlite3 to locate its native
.node file) was not being installed into the local node_modules because
it's a transitive dependency that bun may keep in its global cache.

Adding `bindings` and `file-uri-to-path` as explicit dependencies ensures
they're installed locally and can be properly packaged by electron-builder.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
In bun workspaces, packages are hoisted to the monorepo root node_modules.
Updated electron-builder paths and copy-native-modules script to use
../../node_modules/ instead of the local node_modules/.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 23, 2025

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

Service Status
Neon Database (Neon)

Thank you for your contribution! 🎉


Preview resources have been processed for cleanup

bun creates symlinks for direct dependencies in the workspace's
node_modules, not the root. The explicit dependency additions
(bindings, file-uri-to-path) will make bun create those symlinks.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The better-sqlite3 native module was compiled for bun's Node.js version
(NODE_MODULE_VERSION 127) but Electron 39 requires NODE_MODULE_VERSION 140.

Enabling npmRebuild allows electron-builder to rebuild native modules
for Electron's Node.js version.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
node-pty requires node-addon-api during @electron/rebuild compilation.
Adding as explicit dependency ensures bun creates symlink for it.
Migrations must be outside the asar archive for drizzle-orm to read them.
Using extraResources places them at process.resourcesPath/resources/migrations/
@saddlepaddle saddlepaddle merged commit 9b0647e into main Dec 23, 2025
14 checks passed
@saddlepaddle saddlepaddle deleted the fix/sqlite-bindings branch December 23, 2025 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant