{"record":{"id":"d85bb8c4d2deeda5","repo":"withastro/astro","slug":"packagejsonpath-does-not-contain-a-version-fi","errorCode":null,"errorMessage":"${packageJsonPath} does not contain a \"version\" field.","messagePattern":"(.+?) does not contain a \"version\" field\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/deps/update-example-versions.js","lineNumber":37,"sourceCode":"// Changeset detects workspace packages to publish via `workspaces` in package.json.\n// Although this conflicts with the `pnpm-workspace.yaml` config, it's easier to configure what gets\n// published through this field, so this file also respects this field when updating the versions.\nconst workspaceDirs = await glob(rootPackageJson.workspaces, {\n\tonlyDirectories: true,\n\tcwd: fileURLToPath(rootUrl),\n});\nfor (const workspaceDir of workspaceDirs) {\n\tconst packageJsonPath = path.join(workspaceDir, './package.json');\n\tconst packageJson = await readAndParsePackageJson(packageJsonPath);\n\tif (!packageJson) continue;\n\n\tif (packageJson.private === true) continue;\n\n\tif (!packageJson.name) {\n\t\tthrow new Error(`${packageJsonPath} does not contain a \"name\" field.`);\n\t}\n\tif (!packageJson.version) {\n\t\tthrow new Error(`${packageJsonPath} does not contain a \"version\" field.`);\n\t}\n\n\tpackageToVersions.set(packageJson.name, packageJson.version);\n}\n\n// Update all examples' package.json\nconst exampleDirs = await glob('examples/*', {\n\tonlyDirectories: true,\n\tcwd: fileURLToPath(rootUrl),\n});\nfor (const exampleDir of exampleDirs) {\n\tconst packageJsonPath = path.join(exampleDir, './package.json');\n\tconst packageJson = await readAndParsePackageJson(packageJsonPath);\n\tif (!packageJson) continue;\n\n\t// Update dependencies\n\tfor (const depName of Object.keys(packageJson.dependencies ?? [])) {\n\t\tif (packageToVersions.has(depName)) {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/scripts/deps/update-example-versions.js#L19-L55","documentation":"Thrown immediately after the `name` check in the same loop in `update-example-versions.js`. Once a workspace package has a name, the script also requires a `version` field so it can record the current version to propagate into examples' dependency manifests. A non-private package without `version` cannot be version-synced, so the script aborts.","triggerScenarios":"A non-private workspace `package.json` that declares `name` but no `version`; a package whose version was accidentally removed during a refactor; a newly created package where version was not yet set.","commonSituations":"Template/scaffold drift where `version` is omitted; manual edits to `package.json`; a package bumped to be public (`private` flipped to false) without backfilling `version`.","solutions":["Add a semver `version` field to the offending `package.json` (path is in the message).","If the package is not meant to be published, set `\"private\": true` so it is skipped entirely.","Run the repo's release/version tooling to set the version consistently."],"exampleFix":"// before — packages/my-thing/package.json\n{\n  \"name\": \"@my-scope/thing\",\n  \"private\": false\n}\n\n// after\n{\n  \"name\": \"@my-scope/thing\",\n  \"version\": \"0.1.0\",\n  \"private\": false\n}","handlingStrategy":"validation","validationCode":"import { readPackageJSON } from './util.js';\nimport semver from 'semver';\nasync function workspaceHasVersion(pkgPath: string): Promise<boolean> {\n  const pkg = await readPackageJSON(pkgPath);\n  return pkg.private === true || (typeof pkg.version === 'string' && semver.valid(pkg.version) !== null);\n}","typeGuard":"function isVersionedPublicManifest(m: MinimalManifest): boolean {\n  return m.private === true || typeof m.version === 'string' && m.version.length > 0;\n}","tryCatchPattern":null,"preventionTips":["CI lint asserting every non-private workspace package has a valid semver `version`.","Run the repo's changeset/version tooling before publishing.","Mark unreleased/internal packages `\"private\": true`."],"tags":["release-script","monorepo","package-json","validation","version"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}