{"record":{"id":"2abb73c81cbf65ae","repo":"denoland/deno","slug":"missing-version-in-package-json-of-npm-package","errorCode":null,"errorMessage":"missing version in package.json of npm package","messagePattern":"missing version in package\\.json of npm package","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"cli/tools/publish/unfurl.rs","lineNumber":680,"sourceCode":"  }\n\n  fn find_workspace_npm_dep_version(\n    &self,\n    pkg_name: &str,\n  ) -> Result<Version, anyhow::Error> {\n    // todo(#24612): warn when this is also a jsr package telling\n    // people to map the specifiers in the import map\n    let pkg_json = self\n      .workspace_resolver\n      .package_jsons()\n      .find(|pkg| pkg.name.as_deref() == Some(pkg_name))\n      .ok_or_else(|| {\n        anyhow::anyhow!(\"unable to find npm package in workspace\")\n      })?;\n    if let Some(version) = &pkg_json.version {\n      Ok(Version::parse_from_npm(version)?)\n    } else {\n      Err(anyhow::anyhow!(\n        \"missing version in package.json of npm package\",\n      ))\n    }\n  }\n\n  /// Look up the version constraint for a @types/* package from package.json\n  /// dependencies (including devDependencies) or from the import map.\n  fn find_types_package_version_req(\n    &self,\n    types_package_name: &str,\n    referrer: &ModuleSpecifier,\n  ) -> Option<VersionReq> {\n    // check package.json dependencies\n    let referrer_path = deno_path_util::url_to_file_path(referrer).ok();\n    let referrer_pkg_jsons = referrer_path\n      .as_ref()\n      .map(|path| self.pkg_json_resolver.get_closest_package_jsons(path))\n      .into_iter()","sourceCodeStart":662,"sourceCodeEnd":698,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/cli/tools/publish/unfurl.rs#L662-L698","documentation":"Companion to the workspace npm lookup: a package.json with the matching `name` was found, but it has no `version` field, so there is no version to pin into the unfurled specifier and publish fails. npm packages used as workspace dependencies must declare a semver version.","triggerScenarios":"A workspace member package.json declares `\"name\": \"pkg\"` but omits `\"version\"`, and published source imports that package, so the unfurler cannot pin a version.","commonSituations":"Hand-written package.json for a private workspace library that forgot `version`; scaffolding templates that omit it; malformed versions are a separate failure (Version::parse_from_npm).","solutions":["Add a valid semver `\"version\"` (e.g. \"1.0.0\") to that member's package.json","Make sure the version parses per npm rules: no 'v' prefix, no ranges like ^1.0","Re-run `deno publish --dry-run` to confirm the specifier pins correctly"],"exampleFix":"// before — packages/shared/package.json\n{ \"name\": \"shared-lib\" }\n// after\n{ \"name\": \"shared-lib\", \"version\": \"1.0.0\" }","handlingStrategy":"validation","validationCode":"# every workspace package.json must carry a version\nfor f in $(find . -name package.json -not -path '*/node_modules/*'); do\n  jq -e 'has(\"version\") and (.version | test(\"^\\\\d+\\\\.\\\\d+\\\\.\\\\d+\"))' \"$f\" >/dev/null \\\n    || echo \"missing/invalid version in $f\" >&2\ndone","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Require `name` and `version` in every member package.json via a repo lint","Use a scaffold template that includes both fields","Fix missing versions before release with `deno publish --dry-run` in CI"],"tags":["publish","jsr","npm","package-json","workspace"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}