Skip to content

fix(cli): add runtime-aware bin wrapper for bun/node compatibility#340

Open
JasonOA888 wants to merge 1 commit intotobi:mainfrom
JasonOA888:fix/bun-install-abi
Open

fix(cli): add runtime-aware bin wrapper for bun/node compatibility#340
JasonOA888 wants to merge 1 commit intotobi:mainfrom
JasonOA888:fix/bun-install-abi

Conversation

@JasonOA888
Copy link

Problem

Installing qmd via bun install -g @tobilu/qmd compiles native modules (better-sqlite3) against bun's internal ABI. But the CLI shebang #!/usr/bin/env node runs it with the system Node.js, causing:

Error: The module '.../better_sqlite3.node'
was compiled against a different Node.js version using NODE_MODULE_VERSION 141.
This version of Node.js requires NODE_MODULE_VERSION 127.

Solution

Add a shell wrapper (bin/qmd) that detects the install runtime:

  1. Check for bun.lock/bun.lockb in package directory
  2. Check for BUN_INSTALL environment variable
  3. If either exists, use bun to run the CLI
  4. Otherwise, fall back to node

This ensures native modules run with the same runtime they were compiled for.

Changes

  • Create bin/qmd shell wrapper with runtime detection
  • Update package.json bin entry to use wrapper
  • Add bin/ to files array

Fixes #319

When qmd is installed via `bun install -g`, better-sqlite3 is compiled
against bun's ABI. But the shebang `#!/usr/bin/env node` runs it with
node, causing ABI mismatch errors.

Solution:
- Add bin/qmd shell wrapper that detects install runtime
- Use bun if bun.lock exists or BUN_INSTALL is set
- Fall back to node otherwise
- Update package.json bin entry to use wrapper

This allows both `bun install -g` and `npm install -g` to work correctly.

Fixes tobi#319
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.

bun global install fails when run with node: native module ABI mismatch (better-sqlite3)

1 participant