{"record":{"id":"de2031497a31214e","repo":"abhigyanpatwari/GitNexus","slug":"gitnexus-package-json-version-is-missing-or-not-a","errorCode":null,"errorMessage":"gitnexus/package.json#version is missing or not a string — cannot generate MCP fallback config.","messagePattern":"gitnexus/package\\.json#version is missing or not a string — cannot generate MCP fallback config\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gitnexus/src/cli/setup.ts","lineNumber":42,"sourceCode":"  isEnoent,\n  type EditorId,\n} from './editor-targets.js';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nconst execFileAsync = promisify(execFile);\n\n// Pin the npx fallback to the installed version. Reason: setup.ts writes\n// a config that persists in the user's editor and is invoked on every MCP\n// connect. Pinning to the installed version means subsequent invocations\n// skip the npm-registry metadata roundtrip (and stay reproducible until\n// the user upgrades). The plugin skill mcp.json are likewise pinned and\n// re-stamped every release by scripts/sync-plugin-manifests.mjs (#2445),\n// since they too execute `gitnexus@<version>` on connect. Only the READMEs\n// stay on `gitnexus@latest` — they're quickstart docs, not executed state.\nconst PKG_VERSION = packageVersion();\nif (!PKG_VERSION) {\n  throw new Error(\n    'gitnexus/package.json#version is missing or not a string — cannot generate MCP fallback config.',\n  );\n}\n// Version-pinned ref for the persisted MCP entry — deliberately distinct from\n// the cjs's exported `gitnexus@latest` hint ref (resolve-analyze-cmd.cjs); the\n// two are not unified (see the comment above and that file's MCP_PINNED_REF).\nconst MCP_PINNED_REF = `gitnexus@${PKG_VERSION}`;\n\n/**\n * Build the `command` string written into an editor's hook settings, which the\n * editor shell-evaluates. `hookPath` is already forward-slash-normalized.\n *\n * On POSIX, single-quote the path: a single-quoted shell string expands nothing,\n * so spaces and metacharacters ($, backtick, ;, |, &, newline, parens) in the\n * install path cannot run as commands. The only character needing escaping\n * inside single quotes is the single quote, via the standard `'\\''` idiom\n * (close, literal-quote, reopen). The previous double-quoted `node \"...\"` form\n * left $/backtick live — a code-execution risk for an adversarial $HOME.","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/0d1aed942f0e8b5d3bac27519fff441aceea722d/gitnexus/src/cli/setup.ts#L24-L60","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (gitnexus/package.json)\n{ \"name\": \"gitnexus\" }\n// after\n{ \"name\": \"gitnexus\", \"version\": \"1.14.0\" }","handlingStrategy":"validation","validationCode":"const pkg = require('gitnexus/package.json');\nif (typeof pkg.version !== 'string' || !pkg.version) throw new Error('gitnexus not installed correctly');","typeGuard":"const hasVersion = (pkg: unknown): pkg is { version: string } =>\n  typeof pkg === 'object' && pkg !== null && typeof (pkg as any).version === 'string' && (pkg as any).version.length > 0;","tryCatchPattern":null,"preventionTips":["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"],"tags":["setup","package-version","mcp","installation"],"backgroundTag":"missing-config-value","analyzedSha":"0d1aed942f0e8b5d3bac27519fff441aceea722d","analyzedAt":"2026-09-08T00:40:44.970Z","contentChangedAt":"2026-09-08T00:40:44.970Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}