Skip to content

fix: crm mount crashes under node — replace import.meta.dir + ship FUSE/NFS sources#3

Merged
dzhng merged 1 commit intomainfrom
fix/import-meta-dir-and-fuse-helper-shipping
May 2, 2026
Merged

fix: crm mount crashes under node — replace import.meta.dir + ship FUSE/NFS sources#3
dzhng merged 1 commit intomainfrom
fix/import-meta-dir-and-fuse-helper-shipping

Conversation

@dzhng
Copy link
Copy Markdown
Owner

@dzhng dzhng commented May 2, 2026

Repro

On a fresh install with no pre-existing ~/.crm/bin/crm-fuse:

$ npm install -g @dzhng/crm.cli
$ crm mount ~/crm
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at join (node:path:1269:7)
    at mountLinux (.../dist/cli.js:3414:21)

Root cause

Two compounding bugs:

  1. dist/cli.js runs under #!/usr/bin/env node, but mountLinux / mountDarwin call join(import.meta.dir, '..', '<asset>') to find the helper source. import.meta.dir is a Bun-only extension; under Node it's undefined, so join throws before the rest of the auto-compile path can run.

  2. Even with a working path resolver, the auto-compile path can't find the source — package.json#files ships only ["dist", "README.md", "LICENSE"], so src/fuse-helper.c and src/nfs-server/ aren't in the published npm tarball at all.

Fix

  • Replace import.meta.dir with dirname(fileURLToPath(import.meta.url)), which works under both Bun and Node.
  • Add a resolveAsset(name) helper that looks for the asset in BUNDLE_DIR/<name> (bundle mode) and BUNDLE_DIR/../<name> (source mode), and use it in both mountLinux and mountDarwin.
  • Extend the build script to copy src/fuse-helper.c and src/nfs-server/ into dist/, so they sit next to the bundled cli.js and ship via the existing "files": ["dist"] entry. No package.json#files change needed — only one source of truth for what's published.

Verification

  • bun run build — clean.
  • bun run check-types — clean.
  • test/fuse-smoke/smoke.ts — 4/4 pass.
  • test/fuse.test.ts — 3/4 pass; the 4th test (fuse scenarios > full scenario) times out at 5s, but it does the same on main without my changes (verified by stashing and re-running on main). Pre-existing test flakiness, not introduced by this PR.
  • test/scenarios/* — same 8 timeouts on main and on this branch (also verified by switching). Unrelated.
  • Repro after fix on a real sandbox (Debian, libfuse3-dev installed, no ~/.crm/bin/crm-fuse):
    $ node dist/cli.js mount /tmp/test-fix
    Mounted at /tmp/test-fix (PID 4144017)
    $ ls /tmp/test-fix
    activities  companies  contacts  deals  llm.txt  ...
    

Suggested follow-up (out of scope here)

crm mount errors with exit 1 when called against an already-mounted path — that's intentional, but it makes idempotent setup scripts clunky. A --idempotent (or just exit 0 + a stderr note when the mountpoint is already healthy) flag would let consumers drop their mountpoint -q X || crm mount X guards. Happy to follow up with a separate PR if useful.

🤖 Generated with Claude Code

…works under node

`mount` crashes on a fresh install with `ERR_INVALID_ARG_TYPE` whenever
~/.crm/bin/crm-fuse (or crm-nfs) doesn't already exist:

  TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
      at join (node:path:1269:7)
      at mountLinux (.../dist/cli.js:3414:21)

Two compounding causes:

1. `import.meta.dir` is a Bun-only extension; under the published bin's
   `#!/usr/bin/env node` shebang it's `undefined`, so
   `join(import.meta.dir, '..', 'fuse-helper.c')` throws before it can do
   anything useful.

2. `package.json#files` is `["dist", "README.md", "LICENSE"]`, so even with
   a working path resolver the FUSE/NFS sources aren't shipped to npm —
   the auto-compile step has nothing to compile.

Fix:

- Replace `import.meta.dir` with `dirname(fileURLToPath(import.meta.url))`,
  which works under both Bun and Node.
- Add a `resolveAsset(name)` helper that looks for shipped sources in
  `BUNDLE_DIR/<name>` (bundle mode) and `BUNDLE_DIR/../<name>` (source
  mode), and update `mountLinux` and `mountDarwin` to use it.
- Have the build copy `src/fuse-helper.c` and `src/nfs-server/` into
  `dist/` so they sit next to the bundled `cli.js` and ship via the
  existing `"files": ["dist"]` entry — no `package.json#files` change
  needed.

Verified end-to-end on a fresh sandbox (no pre-existing helper):
`node dist/cli.js mount /tmp/x` now compiles `~/.crm/bin/crm-fuse` and
mounts successfully.
@dzhng dzhng merged commit ef5f5dd into main May 2, 2026
1 check passed
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