withastro/astro · error · Error
${packageJsonPath} does not contain a "version" field.
Error message
${packageJsonPath} does not contain a "version" field. What it means
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.
Source
Thrown at scripts/deps/update-example-versions.js:37
// 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;
// Update dependencies
for (const depName of Object.keys(packageJson.dependencies ?? [])) {
if (packageToVersions.has(depName)) {View on GitHub (pinned to d081033d5f)
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.
Example fix
// before — packages/my-thing/package.json
{
"name": "@my-scope/thing",
"private": false
}
// after
{
"name": "@my-scope/thing",
"version": "0.1.0",
"private": false
} Defensive patterns
Strategy: validation
Validate before calling
import { readPackageJSON } from './util.js';
import semver from 'semver';
async function workspaceHasVersion(pkgPath: string): Promise<boolean> {
const pkg = await readPackageJSON(pkgPath);
return pkg.private === true || (typeof pkg.version === 'string' && semver.valid(pkg.version) !== null);
} Type guard
function isVersionedPublicManifest(m: MinimalManifest): boolean {
return m.private === true || typeof m.version === 'string' && m.version.length > 0;
} Prevention
- 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`.
When it happens
Trigger: 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.
Common situations: 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`.
Related errors
- ${packageJsonPath} does not contain a "name" field.
- UNSUPPORTED_MEDIA_TYPE
- BAD_REQUEST
- CannotExtractFontType
- ExpectedImageOptions
AI-assisted analysis of withastro/astro@d081033d5f (2026-08-12).
Data as JSON: /api/errors/d85bb8c4d2deeda5.
Report an issue: GitHub.