fix(docker): bundle prebuilt better-sqlite3 binding via pnpm deploy#81
Merged
fix(docker): bundle prebuilt better-sqlite3 binding via pnpm deploy#81
Conversation
|
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
0e2e8a7 to
2b92492
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #78 —
Error: Could not locate the bindings filewhen anything inside the Docker image loadsbetter-sqlite3.Root cause
The runtime stage of
packages/context/Dockerfileran:--ignore-scriptsskipsbetter-sqlite3's install script (which normally hasprebuild-installfetch the prebuilt.nodebinary). The package is on disk but its native binding is not, sorequire("better-sqlite3")walks every fallback path and throws.Although
src/database.tsdoestry { 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 --legacyin the build stage to assemble a self-contained folder under/deploythat already contains:dist/package.jsonnode_modules/with the compiledbetter_sqlite3.nodebinaryThe runtime stage then just
COPY --from=build /deploy ./— no second install, no--ignore-scriptsfoot-gun, and no build tools needed in the runtime image.--legacyis required because pnpm 10 otherwise expectsinject-workspace-packages=true; we don't need injection here since@neuledge/contexthas no workspace dependencies.Verified locally
Test plan
docker build -f packages/context/Dockerfile .succeedsnode -e "require('better-sqlite3')"no longer throwsGenerated by Claude Code