{"record":{"id":"432c303ab2ef2b5c","repo":"withastro/astro","slug":"packagejsonpath-does-not-contain-a-name-field","errorCode":null,"errorMessage":"${packageJsonPath} does not contain a \"name\" field.","messagePattern":"(.+?) does not contain a \"name\" field\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/deps/update-example-versions.js","lineNumber":34,"sourceCode":"/** @type {Map<string, string>} */\nconst packageToVersions = new Map();\n\n// 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","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/scripts/deps/update-example-versions.js#L16-L52","documentation":"Thrown by `scripts/deps/update-example-versions.js` while iterating workspace directories. For each non-private workspace package it requires the `package.json` to declare a `name` field, because the script builds a map from package name to version that is later used to rewrite example `package.json` dependency versions. A workspace package missing `name` cannot be keyed into that map, so the script aborts.","triggerScenarios":"A new package added under `packages/` (or another workspace glob match) whose `package.json` has no `name` field; a private package whose `private` field is falsy/missing alongside a missing `name`; an example accidentally matched by the workspace glob.","commonSituations":"A contributor scaffolds a new package from a template that omits `name`; a draft/WIP package committed before being fully configured; the workspace `workspaces` glob in root package.json was broadened to match a directory with an incomplete manifest.","solutions":["Add a unique `name` field to the offending `package.json` (the path is interpolated into the message).","If the package is internal-only and not meant to be published/version-tracked, set `\"private\": true` so the script skips it.","Tighten the root `workspaces` glob so it does not match directories without valid manifests."],"exampleFix":"// before — packages/my-thing/package.json\n{\n  \"version\": \"0.0.1\",\n  \"private\": false\n}\n\n// after\n{\n  \"name\": \"@my-scope/thing\",\n  \"version\": \"0.0.1\",\n  \"private\": false\n}","handlingStrategy":"validation","validationCode":"import { readPackageJSON } from './util.js';\nasync function workspaceHasName(pkgPath: string): Promise<boolean> {\n  const pkg = await readPackageJSON(pkgPath);\n  return Boolean(pkg.name) || pkg.private === true;\n}","typeGuard":"interface MinimalManifest { name?: string; version?: string; private?: boolean }\nfunction isNamedPublicManifest(m: MinimalManifest): boolean {\n  return m.private === true || typeof m.name === 'string' && m.name.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Add a CI lint that asserts every non-private workspace package.json has a `name`.","Use the repo's package template when scaffolding new packages.","Mark internal-only packages `\"private\": true`."],"tags":["release-script","monorepo","package-json","validation"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}