withastro/astro · error · Error
${packageJsonPath} does not contain a "name" field.
Error message
${packageJsonPath} does not contain a "name" field. What it means
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.
Source
Thrown at scripts/deps/update-example-versions.js:34
/** @type {Map<string, string>} */
const packageToVersions = new Map();
// Changeset detects workspace packages to publish via `workspaces` in package.json.
// Although this conflicts with the `pnpm-workspace.yaml` config, it's easier to configure what gets
// published through this field, so this file also respects this field when updating the versions.
const workspaceDirs = await glob(rootPackageJson.workspaces, {
onlyDirectories: true,
cwd: fileURLToPath(rootUrl),
});
for (const workspaceDir of workspaceDirs) {
const packageJsonPath = path.join(workspaceDir, './package.json');
const packageJson = await readAndParsePackageJson(packageJsonPath);
if (!packageJson) continue;
if (packageJson.private === true) continue;
if (!packageJson.name) {
throw new Error(`${packageJsonPath} does not contain a "name" field.`);
}
if (!packageJson.version) {
throw new Error(`${packageJsonPath} does not contain a "version" field.`);
}
packageToVersions.set(packageJson.name, packageJson.version);
}
// Update all examples' package.json
const exampleDirs = await glob('examples/*', {
onlyDirectories: true,
cwd: fileURLToPath(rootUrl),
});
for (const exampleDir of exampleDirs) {
const packageJsonPath = path.join(exampleDir, './package.json');
const packageJson = await readAndParsePackageJson(packageJsonPath);
if (!packageJson) continue;
View on GitHub (pinned to d081033d5f)
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.
Example fix
// before — packages/my-thing/package.json
{
"version": "0.0.1",
"private": false
}
// after
{
"name": "@my-scope/thing",
"version": "0.0.1",
"private": false
} Defensive patterns
Strategy: validation
Validate before calling
import { readPackageJSON } from './util.js';
async function workspaceHasName(pkgPath: string): Promise<boolean> {
const pkg = await readPackageJSON(pkgPath);
return Boolean(pkg.name) || pkg.private === true;
} Type guard
interface MinimalManifest { name?: string; version?: string; private?: boolean }
function isNamedPublicManifest(m: MinimalManifest): boolean {
return m.private === true || typeof m.name === 'string' && m.name.length > 0;
} Prevention
- 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`.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ${packageJsonPath} does not contain a "version" field.
- UNSUPPORTED_MEDIA_TYPE
- BAD_REQUEST
- CannotExtractFontType
- ExpectedImageOptions
AI-assisted analysis of withastro/astro@d081033d5f (2026-08-12).
Data as JSON: /api/errors/432c303ab2ef2b5c.
Report an issue: GitHub.