Skip to content

bug: opencli --version reports 0.0.0 when installed from source + Failed to load module for user clis #788

@AhogeK

Description

@AhogeK

Description

When installing from source (as documented in the README under For Developers), two issues occur simultaneously:

  1. opencli --version always reports 0.0.0 instead of the actual version.
  2. Every command in ~/.opencli/clis/ fails with Failed to load module ... Cannot find module '/Users/<user>/.opencli/src/registry.js'.

Environment

  • Install method: from source (git clonenpm installnpm run buildnpm link / pnpm link --global)
  • Node: v24.14.1 (via nvm)
  • npm: latest
  • OS: macOS
  • opencli version (package.json): 1.6.3

Steps to Reproduce

git clone git@github.com:jackwener/opencli.git && cd opencli
npm install
npm run build
npm link   # or: pnpm link --global
opencli --version
opencli doctor

Root Cause Analysis

Bug 1 — version reports 0.0.0

src/version.ts resolves package.json with one level up from __dirname:

// src/version.ts
const pkgJsonPath = path.resolve(__dirname, '..', 'package.json');

At runtime after npm run build, __dirname is dist/src/. One level up is dist/, where no package.json exists. The try/catch silently falls back to '0.0.0'.

This works fine for npm install -g users because npm automatically includes the root package.json in the published package, placing it at <package-root>/package.json — exactly one level above dist/src/. But when running from a cloned repo, the root package.json is two levels above dist/src/.

Fix:

- const pkgJsonPath = path.resolve(__dirname, '..', 'package.json');
+ const pkgJsonPath = path.resolve(__dirname, '..', '..', 'package.json');

Bug 2 — Failed to load module ~/.opencli/clis/*.js

The postinstall / fetch-adapters.js script downloads pre-compiled .js adapter files into ~/.opencli/clis/. These files contain hardcoded absolute-style imports:

Cannot find module '/Users/<user>/.opencli/src/registry.js'
Cannot find module '/Users/<user>/.opencli/src/errors.js'

However, ~/.opencli/src/ is never created — the core runtime lives inside the npm package's dist/src/, not under ~/.opencli/. These pre-compiled clis appear to have been built against an older layout where the source was symlinked or copied into ~/.opencli/src/.

Workaround (user-side): rm -rf ~/.opencli/clis/ causes opencli to fall back to the built-in YAML-driven commands in dist/clis/, avoiding the broken imports entirely.


Expected Behavior

  • opencli --version1.6.3
  • opencli doctor → no Failed to load module warnings

Actual Behavior

  • opencli --version0.0.0
  • Hundreds of ⚠ Failed to load module warnings for every adapter in ~/.opencli/clis/

Suggested Fix

For Bug 1, the one-line change above in src/version.ts is sufficient. It is backward-compatible: when installed via npm install -g, the root package.json is still two levels above dist/src/ inside the installed package directory.

For Bug 2, the pre-compiled .js files distributed by fetch-adapters.js may need to be rebuilt with correct import paths that resolve against the npm package's installed location rather than ~/.opencli/src/.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions