openai/codex-plugin-cc · error · Error

package.json version must be a string.

Error message

package.json version must be a string.

What it means

Thrown by readPackageVersion() when package.json's `version` field exists but is not a string (e.g. a number, null, object). It is a type guard run before validateVersion, because the regex test would coerce/throw on non-strings. Used by the --check path that infers the expected version from package.json.

Source

Thrown at scripts/bump-version.mjs:153

  const plugin = json.plugins?.find((entry) => entry?.name === "codex");
  requireObject(plugin, ".claude-plugin/marketplace.json plugins[codex]");
  return plugin;
}

function readJson(root, file) {
  const filePath = path.join(root, file);
  return JSON.parse(fs.readFileSync(filePath, "utf8"));
}

function writeJson(root, file, json) {
  const filePath = path.join(root, file);
  fs.writeFileSync(filePath, `${JSON.stringify(json, null, 2)}\n`);
}

function readPackageVersion(root) {
  const packageJson = readJson(root, "package.json");
  if (typeof packageJson.version !== "string") {
    throw new Error("package.json version must be a string.");
  }
  validateVersion(packageJson.version);
  return packageJson.version;
}

function checkVersions(root, expectedVersion) {
  const mismatches = [];

  for (const target of TARGETS) {
    const json = readJson(root, target.file);
    for (const value of target.values) {
      const actual = value.get(json);
      if (actual !== expectedVersion) {
        mismatches.push(`${target.file} ${value.label}: expected ${expectedVersion}, found ${actual ?? "<missing>"}`);
      }
    }
  }

View on GitHub (pinned to db52e28f4d)

Solutions

  1. Edit package.json so `version` is a quoted semver string: "version": "1.0.0".
  2. If the field is missing, add it under the top-level object.
  3. Re-validate the JSON with `node -e "JSON.parse(require('fs').readFileSync('package.json','utf8'))"` to catch corruption.

Example fix

// before — package.json
{ "name": "codex", "version": 1.0 }

// after
{ "name": "codex", "version": "1.0.0" }
Defensive patterns

Strategy: type-guard

Validate before calling

function readSafePackageVersion(root) {
  const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
  if (typeof pkg.version !== "string") {
    throw new Error("package.json version missing or not a string.");
  }
  return pkg.version;
}

Type guard

function hasStringVersion(pkg) {
  return pkg != null && typeof pkg === "object" && typeof pkg.version === "string";
}

Try / catch

try {
  readPackageVersion(root);
} catch (err) {
  if (/version must be a string/.test(err.message)) {
    // prompt user to fix package.json before retrying
  } else throw err;
}

Prevention

When it happens

Trigger: Running `node scripts/bump-version.mjs --check` (no version) on a repo whose package.json has `"version": 1.0.0` (numeric) or `"version": null` or no version field at all (typeof undefined !== 'string').

Common situations: package.json hand-edited with an unquoted numeric version; version field deleted; a JSON5/JSON-with-comments artifact; tooling that wrote a non-string version.

Related errors


AI-assisted analysis of openai/codex-plugin-cc@db52e28f4d (2026-08-13). Data as JSON: /api/errors/d65f6b81f32bbd49. Report an issue: GitHub.