angular/angular-cli · warning

Could not resolve '@angular/core/package.json' from '${works

Error message

Could not resolve '@angular/core/package.json' from '${workspacePath}'. Is Angular installed in this project? Falling back to the bundled guide.

What it means

To load version-specific best practices, the tool resolves `@angular/core/package.json` from the workspace using createRequire. If the resolution fails, Angular is not installed (or not resolvable) in that workspace, so the tool warns and falls back to the bundled guide.

Source

Thrown at packages/angular/cli/src/commands/mcp/tools/best-practices.ts:126

      return undefined;
    }

    if (!isAllowed) {
      throw new Error(
        `Workspace path is outside the allowed MCP roots: ${workspacePath}. ` +
          "You can use 'list_projects' to find available workspaces.",
      );
    }
  }

  // 1. Resolve the path to package.json
  let pkgJsonPath: string;
  try {
    const workspaceRequire = createRequire(workspacePath);
    pkgJsonPath = workspaceRequire.resolve('@angular/core/package.json');
  } catch (e) {
    logger.warn(
      `Could not resolve '@angular/core/package.json' from '${workspacePath}'. ` +
        'Is Angular installed in this project? Falling back to the bundled guide.',
    );

    return undefined;
  }

  // 2. Read and parse package.json, then find and read the guide.
  try {
    const pkgJsonContent = await readFile(pkgJsonPath, 'utf-8');
    const pkgJson = JSON.parse(pkgJsonContent);
    const bestPracticesInfo = pkgJson['angular']?.bestPractices;

    if (
      bestPracticesInfo &&
      bestPracticesInfo.format === 'markdown' &&
      typeof bestPracticesInfo.path === 'string'
    ) {

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Run `npm install` (or your package manager's install) in the workspace so @angular/core exists.
  2. Point the tool at the actual Angular workspace root, not an unrelated directory.
  3. If using pnpm/Yarn PnP, ensure the setup allows standard Node require resolution, or rely on the bundled guide fallback.

Example fix

// before: empty workspace
my-app/ (no node_modules)
// after
npm install
# @angular/core/package.json resolvable, version-specific guide loads
Defensive patterns

Strategy: validation

Validate before calling

import { createRequire } from 'node:module';
import { existsSync } from 'node:fs';
if (!existsSync('node_modules/@angular/core/package.json')) {
  console.warn('@angular/core not installed; run `npm install` first.');
}

Try / catch

try {
  const pkgJsonPath = createRequire(workspacePath).resolve('@angular/core/package.json');
} catch {
  return bundledGuide(); // graceful fallback
}

Prevention

When it happens

Trigger: createRequire(workspacePath).resolve('@angular/core/package.json') throws because node_modules lacks @angular/core or module resolution fails from that path.

Common situations: Running the MCP tool in a non-Angular directory; dependencies not installed (`npm install` not run); pnpm/yarn PnP layouts where resolution via Node require fails; monorepo subfolders without local node_modules.

Related errors


AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30). Data as JSON: /api/errors/8ea2bf7698685980. Report an issue: GitHub.