withastro/astro · error · Error

Unable to resolve "${packageName}". Is it a dependency of th

Error message

Unable to resolve "${packageName}". Is it a dependency of the workspace root?

What it means

Thrown by `getWorkspacePackageVersion` in the monorepo build script when a requested internal package name is not listed in the root `package.json`'s `dependencies` or `devDependencies`. The script reads the workspace root manifest, merges both dep maps, and looks up the name; a miss means the build cannot determine which version of the internal package to use.

Source

Thrown at scripts/cmd/build.js:179

	return Object.entries(define);
}

async function readPackageJSON(path) {
	return await fs.readFile(path, { encoding: 'utf8' }).then((res) => JSON.parse(res));
}

async function getInternalPackageVersion(path) {
	return readPackageJSON(path).then((res) => res.version);
}

async function getWorkspacePackageVersion(packageName) {
	const { dependencies, devDependencies } = await readPackageJSON(
		new URL('../../package.json', import.meta.url),
	);
	const deps = { ...dependencies, ...devDependencies };
	const version = deps[packageName];
	if (!version) {
		throw new Error(
			`Unable to resolve "${packageName}". Is it a dependency of the workspace root?`,
		);
	}
	return version.replace(/^\D+/, '');
}

View on GitHub (pinned to d081033d5f)

Solutions

  1. Add the missing package to the root `package.json` under `dependencies` or `devDependencies` (commonly as `workspace:*` or a version range), then `pnpm install`.
  2. Verify the spelling/scope of the package name matches the `name` field in its own `package.json`.
  3. If the package should not be a root dependency, change the caller to resolve its version from its own `package.json` (e.g. via `getInternalPackageVersion`) instead of the workspace root.

Example fix

// before — root package.json missing the entry
"dependencies": { "astro": "workspace:*" }

// after — add the internal package
"dependencies": { "astro": "workspace:*", "@astrojs/jsx": "workspace:*" }
Defensive patterns

Strategy: validation

Validate before calling

import { readPackageJSON } from './util.js';
async function isInWorkspaceRoot(packageName: string): Promise<boolean> {
  const { dependencies = {}, devDependencies = {} } =
    await readPackageJSON(new URL('../../package.json', import.meta.url));
  return packageName in dependencies || packageName in devDependencies;
}
// guard before calling getWorkspacePackageVersion

Type guard

function isRootDep(rootManifest: { dependencies?: Record<string,string>; devDependencies?: Record<string,string> }, name: string): boolean {
  return Boolean(rootManifest.dependencies?.[name] ?? rootManifest.devDependencies?.[name]);
}

Prevention

When it happens

Trigger: Calling the build script with a `--package <name>` (or internal lookup) for a package that is not hoisted to the workspace root — e.g. a new integration that was added to `packages/integrations/` but never added to the root manifest; a renamed package; a package that is only a transitive dependency.

Common situations: A contributor adds a new workspace package but forgets to add it to root `package.json`; renaming a package without updating the root deps; running a build step targeting a package that exists in `packages/` but is consumed only via workspaces, not listed at root.

Related errors


AI-assisted analysis of withastro/astro@d081033d5f (2026-08-12). Data as JSON: /api/errors/b5ec2a9423faf664. Report an issue: GitHub.