Skip to content

chore(native): add pnpm check:native mismatch detection script - #248

Merged
h4yfans merged 1 commit into
mainfrom
debt/phase-6-u1-check-native
Apr 16, 2026
Merged

chore(native): add pnpm check:native mismatch detection script#248
h4yfans merged 1 commit into
mainfrom
debt/phase-6-u1-check-native

Conversation

@h4yfans

@h4yfans h4yfans commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Part of Phase 6 Tech Debt Remediation — see .claude/plans/tech-debt-remediation.md § 6.1.

Summary

  • apps/desktop/scripts/check-native.js — cross-platform Node script that detects NODE_MODULE_VERSION mismatch by attempting to require() each native module in a child process and parsing any ERR_DLOPEN_FAILED output.
  • Root pnpm check:native wired next to other check:* scripts.
  • Reads the stamp file written by ensure-native.sh to report last build target + suggest the right pnpm rebuild:{node,electron} fix.

Why

ERR_DLOPEN_FAILED has repeatedly burned cycles — per project memory, caused autoOpenLastVault to silently fail and E2E tests to time out on .bn-container. Turning an opaque dlopen error into a one-command fix removes the landmine.

Smoke test (run locally)

pnpm check:native
# [check:native] OK — modules load under node (stamp: node)

# Force mismatch:
bash apps/desktop/scripts/ensure-native.sh electron
pnpm check:native
# exits 1 with "pnpm rebuild:node" suggestion

# Restore:
bash apps/desktop/scripts/ensure-native.sh node

Test plan

  • Script exits 0 when modules match runtime (verified locally before push)
  • CI: pnpm typecheck && pnpm test green (no source touched)

Adds a cross-platform Node script that detects NODE_MODULE_VERSION
mismatch between the built native modules (better-sqlite3, keytar)
and the current runtime (Node or Electron), and prints the correct
fix command.

- New: apps/desktop/scripts/check-native.js
- New: pnpm check:native in root package.json

Detection: spawns a child Node process that requires each native
module; on ERR_DLOPEN_FAILED, parses the compiled/expected ABI from
the error message. Reports the stamp file's last build target and
suggests pnpm rebuild:node or pnpm rebuild:electron as appropriate.

Example output (mismatch):
  [check:native] NODE_MODULE_VERSION mismatch — 2 module(s) failed to load under node:
    - better-sqlite3: compiled for ABI 141, runtime needs ABI 133
    - keytar: compiled for ABI 141, runtime needs ABI 133

  [check:native] stamp says last build target was "electron"; current runtime is "node".
  [check:native] fix:
      pnpm rebuild:node           # to run tests/scripts under Node
      pnpm rebuild:electron       # to run the Electron app (pnpm dev)

Plan: .claude/plans/tech-debt-remediation.md § 6.1
@h4yfans
h4yfans merged commit 6b9af1a into main Apr 16, 2026
4 checks passed
@h4yfans
h4yfans deleted the debt/phase-6-u1-check-native branch April 16, 2026 22:22
h4yfans added a commit that referenced this pull request May 6, 2026
Adds a cross-platform Node script that detects NODE_MODULE_VERSION
mismatch between the built native modules (better-sqlite3, keytar)
and the current runtime (Node or Electron), and prints the correct
fix command.

- New: apps/desktop/scripts/check-native.js
- New: pnpm check:native in root package.json

Detection: spawns a child Node process that requires each native
module; on ERR_DLOPEN_FAILED, parses the compiled/expected ABI from
the error message. Reports the stamp file's last build target and
suggests pnpm rebuild:node or pnpm rebuild:electron as appropriate.

Example output (mismatch):
  [check:native] NODE_MODULE_VERSION mismatch — 2 module(s) failed to load under node:
    - better-sqlite3: compiled for ABI 141, runtime needs ABI 133
    - keytar: compiled for ABI 141, runtime needs ABI 133

  [check:native] stamp says last build target was "electron"; current runtime is "node".
  [check:native] fix:
      pnpm rebuild:node           # to run tests/scripts under Node
      pnpm rebuild:electron       # to run the Electron app (pnpm dev)

Plan: .claude/plans/tech-debt-remediation.md § 6.1
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.

1 participant