Skip to content

fix(docker): bundle prebuilt better-sqlite3 binding via pnpm deploy#81

Merged
moshest merged 1 commit intomainfrom
claude/investigate-issue-78-jUxwo
May 6, 2026
Merged

fix(docker): bundle prebuilt better-sqlite3 binding via pnpm deploy#81
moshest merged 1 commit intomainfrom
claude/investigate-issue-78-jUxwo

Conversation

@moshest
Copy link
Copy Markdown
Member

@moshest moshest commented May 6, 2026

Summary

Fixes #78Error: Could not locate the bindings file when anything inside the Docker image loads better-sqlite3.

Root cause

The runtime stage of packages/context/Dockerfile ran:

npm install --omit=dev --ignore-scripts

--ignore-scripts skips better-sqlite3's install script (which normally has prebuild-install fetch the prebuilt .node binary). The package is on disk but its native binding is not, so require("better-sqlite3") walks every fallback path and throws.

Although src/database.ts does try { require("better-sqlite3") } catch { ... fall back to sql.js }, any other tool inside the container (e.g. npm install <pkg> while exec'd in) that touches the module hits the raw error.

Fix

Use pnpm deploy --prod --legacy in the build stage to assemble a self-contained folder under /deploy that already contains:

  • dist/
  • package.json
  • node_modules/ with the compiled better_sqlite3.node binary

The runtime stage then just COPY --from=build /deploy ./ — no second install, no --ignore-scripts foot-gun, and no build tools needed in the runtime image.

--legacy is required because pnpm 10 otherwise expects inject-workspace-packages=true; we don't need injection here since @neuledge/context has no workspace dependencies.

Verified locally

$ pnpm --filter @neuledge/context deploy --prod --legacy /tmp/deploy-test
$ ls /tmp/deploy-test/node_modules/better-sqlite3/build/Release/
better_sqlite3.node
$ cd /tmp/deploy-test && node -e "const Db=require('better-sqlite3'); const db=new Db(':memory:'); db.exec('CREATE TABLE t(x); INSERT INTO t VALUES(1)'); console.log(db.prepare('SELECT x FROM t').get());"
{ x: 1 }

Test plan

  • docker build -f packages/context/Dockerfile . succeeds
  • Container starts and serves on 8080
  • Inside the container, node -e "require('better-sqlite3')" no longer throws

Generated by Claude Code

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 6, 2026

⚠️ No Changeset found

Latest commit: 2b92492

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

The runtime stage previously ran `npm install --omit=dev --ignore-scripts`,
which skips better-sqlite3's install script and leaves the native binary
unbuilt. Anything that loads better-sqlite3 inside the container then
crashes with "Could not locate the bindings file".

Use `pnpm deploy --prod --legacy` in the build stage to assemble a
self-contained folder that already includes the compiled .node binary,
and copy that into the runtime stage. No second install is needed.

Closes #78
@moshest moshest force-pushed the claude/investigate-issue-78-jUxwo branch from 0e2e8a7 to 2b92492 Compare May 6, 2026 06:54
@moshest moshest merged commit 2287126 into main May 6, 2026
3 checks passed
@moshest moshest deleted the claude/investigate-issue-78-jUxwo branch May 6, 2026 06:55
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.

Docker deployment: Error: Could not locate the bindings file

2 participants