{"record":{"id":"c880a6eaa1025a47","repo":"clockworklabs/SpacetimeDB","slug":"missing-version-field-in-typescript-bindings-pac","errorCode":null,"errorMessage":"Missing \"version\" field in TypeScript bindings package.json","messagePattern":"Missing \"version\" field in TypeScript bindings package\\.json","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/build.rs","lineNumber":491,"sourceCode":"            if let Some(version) = version_opt {\n                versions.insert(name.clone(), version);\n            }\n        }\n    }\n\n    Ok((edition, versions))\n}\n\nfn extract_ts_bindings_version(path: &Path) -> io::Result<String> {\n    let content = fs::read_to_string(path)?;\n    let parsed: serde_json::Value =\n        serde_json::from_str(&content).map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?;\n    parsed\n        .get(\"version\")\n        .and_then(serde_json::Value::as_str)\n        .map(|s| s.to_string())\n        .ok_or_else(|| {\n            io::Error::new(\n                io::ErrorKind::InvalidData,\n                \"Missing \\\"version\\\" field in TypeScript bindings package.json\",\n            )\n        })\n}\n\nfn normalize_version(version: &str) -> String {\n    version.trim().trim_start_matches('=').to_string()\n}\n\nfn write_if_changed(path: &Path, contents: &[u8]) -> io::Result<()> {\n    match fs::read(path) {\n        Ok(existing) if existing == contents => Ok(()),\n        _ => {\n            if let Some(parent) = path.parent() {\n                fs::create_dir_all(parent)?;\n            }\n            let mut file = fs::File::create(path)?;","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/cli/build.rs#L473-L509","documentation":"Raised by extract_ts_bindings_version in the CLI build script while compiling the `spacetime` CLI. The script reads crates/bindings-typescript/package.json to embed the TypeScript bindings version next to the workspace metadata used by `spacetime init` templates. If the parsed JSON has no top-level version field, or version is not a JSON string, it returns InvalidData with this message and the .expect() at build.rs:109 panics the build.","triggerScenarios":"Building the SpacetimeDB CLI when crates/bindings-typescript/package.json has had its \"version\" field removed or set to a non-string (number, object) - e.g. by release automation, a bad merge, or regenerating the file from a partial template.","commonSituations":"Version-bump scripts that rewrite package.json and drop fields; JSON merge conflicts resolved by hand; vendored copies where the file was regenerated without version.","solutions":["Add a string \"version\" field to crates/bindings-typescript/package.json, e.g. \"version\": \"1.0.0\" consistent with the release.","Restore the file from git history if it was mangled: `git checkout HEAD -- crates/bindings-typescript/package.json`.","Fix the release/version-bump script so it always preserves the version field when rewriting package.json."],"exampleFix":"// before (crates/bindings-typescript/package.json)\n{\n  \"name\": \"bindings-typescript\"\n}\n\n// after\n{\n  \"name\": \"bindings-typescript\",\n  \"version\": \"1.0.0\"\n}","handlingStrategy":"validation","validationCode":"let pkg: serde_json::Value =\n    serde_json::from_str(&std::fs::read_to_string(\"crates/bindings-typescript/package.json\")?)?;\nanyhow::ensure!(\n    pkg.get(\"version\").map(|v| v.is_string()).unwrap_or(false),\n    \"package.json must carry a string \\\"version\\\" field\"\n);","typeGuard":null,"tryCatchPattern":"match extract_ts_bindings_version(&ts_bindings_package) {\n    Ok(v) => v,\n    Err(e) if e.kind() == io::ErrorKind::InvalidData => {\n        // restore the file from git and rebuild: git checkout HEAD -- crates/bindings-typescript/package.json\n        return Err(anyhow!(\"{e}\"));\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Validate package.json with a schema check in CI that requires a string version field.","Make version-bump scripts patch fields in place rather than regenerating the whole file.","Re-run the CLI build immediately after touching bindings-typescript/package.json to catch stripped fields early."],"tags":["json","package-json","build-script","spacetimedb-cli","version"],"backgroundTag":"missing-package-version","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}