abhigyanpatwari/GitNexus · error · Error
gitnexus/package.json#version is missing or not a string — c
Error message
gitnexus/package.json#version is missing or not a string — cannot generate MCP fallback config.
What it means
setup.ts reads the installed gitnexus package version via packageVersion() to generate a version-pinned MCP fallback config. If the version is missing or not a string (package.json unreadable/corrupted or the resolver failed), setup throws because it refuses to emit an unpinned or empty version reference.
Source
Thrown at gitnexus/src/cli/setup.ts:42
isEnoent,
type EditorId,
} from './editor-targets.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const execFileAsync = promisify(execFile);
// Pin the npx fallback to the installed version. Reason: setup.ts writes
// a config that persists in the user's editor and is invoked on every MCP
// connect. Pinning to the installed version means subsequent invocations
// skip the npm-registry metadata roundtrip (and stay reproducible until
// the user upgrades). The plugin skill mcp.json are likewise pinned and
// re-stamped every release by scripts/sync-plugin-manifests.mjs (#2445),
// since they too execute `gitnexus@<version>` on connect. Only the READMEs
// stay on `gitnexus@latest` — they're quickstart docs, not executed state.
const PKG_VERSION = packageVersion();
if (!PKG_VERSION) {
throw new Error(
'gitnexus/package.json#version is missing or not a string — cannot generate MCP fallback config.',
);
}
// Version-pinned ref for the persisted MCP entry — deliberately distinct from
// the cjs's exported `gitnexus@latest` hint ref (resolve-analyze-cmd.cjs); the
// two are not unified (see the comment above and that file's MCP_PINNED_REF).
const MCP_PINNED_REF = `gitnexus@${PKG_VERSION}`;
/**
* Build the `command` string written into an editor's hook settings, which the
* editor shell-evaluates. `hookPath` is already forward-slash-normalized.
*
* On POSIX, single-quote the path: a single-quoted shell string expands nothing,
* so spaces and metacharacters ($, backtick, ;, |, &, newline, parens) in the
* install path cannot run as commands. The only character needing escaping
* inside single quotes is the single quote, via the standard `'\''` idiom
* (close, literal-quote, reopen). The previous double-quoted `node "..."` form
* left $/backtick live — a code-execution risk for an adversarial $HOME.View on GitHub (pinned to 0d1aed942f)
Solutions
- Reinstall the package: npm install -g gitnexus (or npm install in the workspace).
- Verify gitnexus/package.json contains a string version field; restore it if edited.
- Run from the published CLI rather than a partial source checkout, or build first (npm run build).
- Clear node_modules and reinstall if the install is corrupted.
Example fix
// before (gitnexus/package.json)
{ "name": "gitnexus" }
// after
{ "name": "gitnexus", "version": "1.14.0" } Defensive patterns
Strategy: validation
Validate before calling
const pkg = require('gitnexus/package.json');
if (typeof pkg.version !== 'string' || !pkg.version) throw new Error('gitnexus not installed correctly'); Type guard
const hasVersion = (pkg: unknown): pkg is { version: string } =>
typeof pkg === 'object' && pkg !== null && typeof (pkg as any).version === 'string' && (pkg as any).version.length > 0; Prevention
- Run setup only after a complete npm install of the package
- Don't strip package.json when bundling/copying the CLI
- Verify `gitnexus --version` works before running setup
When it happens
Trigger: Running `gitnexus setup` from a source checkout or broken install where gitnexus/package.json lacks a valid #version field, or packageVersion() cannot resolve the package metadata.
Common situations: Developing inside the monorepo without building/installing the package, a corrupted node_modules after a failed install, or packaging the CLI without its package.json.
Understand the failure class
Background: "missing required config value" errors: why libraries refuse to start when a configuration key is empty, unset, or blank — this error's family across 48 libraries.
Related errors
- Missing Content-Length header from MCP client
- Invalid Content-Length header from MCP client
- Content-Length ${contentLength} exceeds maximum allowed size
- Refusing to start the MCP HTTP server on a non-loopback host
- ${source} must be a positive integer.
AI-assisted analysis of abhigyanpatwari/GitNexus@0d1aed942f (2026-09-08).
Data as JSON: /api/errors/de2031497a31214e.
Report an issue: GitHub.