angular/angular-cli · error · Error
Could not find a package.json. Are you in a Node project?
Error message
Could not find a package.json. Are you in a Node project?
What it means
Thrown at the start of building the update plan when no package.json exists at the workspace root (options.workspaceRoot or process.cwd()). ng update requires a Node project root to read dependencies from, so it aborts immediately.
Source
Thrown at packages/angular/cli/src/commands/update/update-resolver.ts:872
`Please perform the following steps to update:\n` +
` 1. Manually update the versions for these packages in your catalog configuration file ` +
`(e.g., pnpm-workspace.yaml or .yarnrc.yml).\n` +
` 2. Run '${installCmd}' to install the updated versions.\n` +
` 3. Run the following command(s) from the workspace root to execute the migration schematics:\n` +
`${migrationCommands}`,
);
}
}
export async function resolveUserUpdatePlan(
options: UpdateResolverOptions,
packageManager: PackageManager,
logger: logging.LoggerApi,
): Promise<UpdatePlan> {
const workspaceRoot = options.workspaceRoot ?? process.cwd();
const packageJsonPath = path.join(workspaceRoot, 'package.json');
if (!existsSync(packageJsonPath)) {
throw new Error('Could not find a package.json. Are you in a Node project?');
}
const rawJson = readFileSync(packageJsonPath, 'utf8');
const packageJsonContent = JSON.parse(rawJson) as PackageManifest;
const getDependencies = (deps: Record<string, string> | undefined) =>
Object.entries(deps ?? {}).map(([name, range]) => [name, range] as const);
const allRawDeps = [
...getDependencies(packageJsonContent.dependencies),
...getDependencies(packageJsonContent.devDependencies),
...getDependencies(packageJsonContent.peerDependencies),
];
const npmDeps = new Map(
allRawDeps.filter(([name, specifier]) => {
try {
return isPkgFromRegistry(name, specifier);View on GitHub (pinned to bb72145f9a)
Solutions
- cd into the directory containing package.json (usually the repo root) and rerun.
- Pass the correct root explicitly: ng update --workspace-root /path/to/project.
- Create a package.json if this genuinely is a Node project (npm init).
- Verify the file exists: ls package.json in the directory you run from.
Example fix
// before ~/projects $ ng update # no package.json here // after cd ~/projects/my-app ng update
Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from 'fs';
import { resolve } from 'path';
if (!existsSync(resolve(workspaceRoot ?? process.cwd(), 'package.json'))) {
throw new Error('Not a Node project root: package.json missing');
} Try / catch
try {
await ngUpdate(packages);
} catch (e) {
if (e.message.includes('Could not find a package.json')) {
// retry with an explicit workspace root pointing at the project directory
}
} Prevention
- Run ng update from the directory containing package.json.
- Set --workspace-root explicitly in CI scripts.
- Never rename or delete package.json while tooling runs.
- Check `pwd` when a fresh shell reports odd failures.
When it happens
Trigger: Running `ng update` outside any Node/JavaScript project directory; wrong --workspace-root (or CWD) pointing at an empty folder; package.json deleted or renamed; running from a subdirectory without workspace root detection.
Common situations: Running the command in a fresh terminal opened at the home directory; CI step with incorrect working directory; monorepo where the CLI was invoked from a non-root folder without the workspace flag.
Related errors
- The current directory resolves to a workspace outside the al
- Could not find ${level} workspace.
- Could not find a ${level} workspace. Are you in a project?
- Cannot determine project for command. This is a multi-projec
- A workspace is required for this command.
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/7d344dd0d0bfbfa1.
Report an issue: GitHub.