Skip to content

fix: native loader fallback to per-platform sub-package when postinstall is skipped#21

Open
tupe12334 wants to merge 1 commit into
LadybugDB:mainfrom
tupe12334:fix/native-loader-subpackage-fallback
Open

fix: native loader fallback to per-platform sub-package when postinstall is skipped#21
tupe12334 wants to merge 1 commit into
LadybugDB:mainfrom
tupe12334:fix/native-loader-subpackage-fallback

Conversation

@tupe12334

Copy link
Copy Markdown

Summary

The native addon loader (src_js/lbug_native.js) only looked for lbugjs.node inside the main package directory, where install.js (postinstall) copies it from the per-platform sub-package. Environments that skip lifecycle scripts never run install.js, so the copy is never made and require fails at runtime with ERR_DLOPEN_FAILED — even though the prebuilt binary is present in @ladybugdb/core-<platform>-<arch>.

Reproduction

pnpm dlx gitnexus@latest serve

On macOS arm64 / Node v25.9.0 / @ladybugdb/core 0.16.1 this throws:

Error: dlopen(.../@ladybugdb/core/lbugjs.node, 0x0001): tried: '.../@ladybugdb/core/lbugjs.node' (no such file)
  code: 'ERR_DLOPEN_FAILED'

This also affects pnpx, npm install --ignore-scripts, and sandboxed installs.

Change

src_js/lbug_native.js now resolves the addon path at runtime:

  1. Prefer the in-package lbugjs.node (the postinstall-copied path, unchanged for normal installs).
  2. If it is missing, fall back to resolving the binary directly from the per-platform sub-package using the same require.resolve(${pkgName}-${platform}-${arch}/package.json, { paths: [__dirname] }) logic that install.js already uses.
  3. If neither exists, keep the original in-package path so dlopen surfaces the original error.

Both the Linux (RTLD_LAZY | RTLD_GLOBAL) and non-Linux dlopen branches 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

…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]>
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.

Bug: native addon load fails when postinstall is skipped (pnpm dlx / --ignore-scripts) despite per-platform binary being present

1 participant