fix: native loader fallback to per-platform sub-package when postinstall is skipped#21
Open
tupe12334 wants to merge 1 commit into
Open
Conversation
…missing The runtime loader only looked for lbugjs.node inside the main package directory, where install.js copies it during postinstall. Environments that skip lifecycle scripts (pnpm dlx, pnpx, --ignore-scripts, sandboxed installs) never run install.js, so the copy is absent and the loader fails with ERR_DLOPEN_FAILED even though the prebuilt binary is present in the @ladybugdb/core-<platform>-<arch> sub-package. Resolve the binary at runtime: prefer the in-package copy, and when it is missing, fall back to the per-platform sub-package using the same require.resolve logic install.js already uses. Fixes LadybugDB#20 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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
The native addon loader (
src_js/lbug_native.js) only looked forlbugjs.nodeinside the main package directory, whereinstall.js(postinstall) copies it from the per-platform sub-package. Environments that skip lifecycle scripts never runinstall.js, so the copy is never made andrequirefails at runtime withERR_DLOPEN_FAILED— even though the prebuilt binary is present in@ladybugdb/core-<platform>-<arch>.Reproduction
On macOS arm64 / Node v25.9.0 /
@ladybugdb/core0.16.1 this throws:This also affects
pnpx,npm install --ignore-scripts, and sandboxed installs.Change
src_js/lbug_native.jsnow resolves the addon path at runtime:lbugjs.node(the postinstall-copied path, unchanged for normal installs).require.resolve(${pkgName}-${platform}-${arch}/package.json, { paths: [__dirname] })logic thatinstall.jsalready uses.dlopensurfaces the original error.Both the Linux (
RTLD_LAZY | RTLD_GLOBAL) and non-Linuxdlopenbranches use the resolved path. No native rebuild is required; this is a pure JS loader change.Notes
This is distinct from #436 / #303 (there the prebuilt binary was missing/unpublished). Here the binary is published and present in the sub-package — the only gap was that the runtime loader had no fallback when postinstall did not run.
Fixes #20
🤖 Generated with Claude Code