{"record":{"id":"65b311bd367e2d04","repo":"angular/angular-cli","slug":"could-not-find-angular-json","errorCode":null,"errorMessage":"Could not find (/.angular.json)","messagePattern":"Could not find \\(/\\.angular\\.json\\)","errorType":"exception","errorClass":"SchematicsException","httpStatus":null,"severity":"error","filePath":"packages/angular/cli/src/command-builder/utilities/schematic-engine-host.ts","lineNumber":112,"sourceCode":"\n      return { ref: factory, path: schematicPath };\n    }\n\n    // All other schematics use default behavior\n    return super._resolveReferenceString(refString, parentPath, collectionDescription);\n  }\n}\n\n/**\n * Minimal shim modules for legacy deep imports of `@schematics/angular`\n */\nconst legacyModules: Record<string, unknown> = {\n  '@schematics/angular/utility/config': {\n    getWorkspace(host: Tree) {\n      const path = '/.angular.json';\n      const data = host.read(path);\n      if (!data) {\n        throw new SchematicsException(`Could not find (${path})`);\n      }\n\n      return parseJson(data.toString(), [], { allowTrailingComma: true });\n    },\n  },\n  '@schematics/angular/utility/project': {\n    buildDefaultPath(project: { sourceRoot?: string; root: string; projectType: string }): string {\n      const root = project.sourceRoot ? `/${project.sourceRoot}/` : `/${project.root}/src/`;\n\n      return `${root}${project.projectType === 'application' ? 'app' : 'lib'}`;\n    },\n  },\n};\n\n/**\n * Wrap a JavaScript file in a VM context to allow specific Angular dependencies to be redirected.\n * This VM setup is ONLY intended to redirect dependencies.\n *","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/command-builder/utilities/schematic-engine-host.ts#L94-L130","documentation":"This SchematicsException is thrown by the legacy '@schematics/angular/utility/config' getWorkspace shim in the Angular CLI's SchematicEngineHost. When a schematic asks for the workspace configuration, the shim reads the virtual '/.angular.json' path from the host tree and, if no data exists, throws 'Could not find (/.angular.json)'. It exists to keep old schematics (written before angular.json replaced .angular.json) working with modern workspaces.","triggerScenarios":"A schematic requires '@schematics/angular/utility/config' and calls its getWorkspace(host) while the host tree contains no '/.angular.json' file — i.e. the workspace config is named 'angular.json' (modern default) or is missing entirely from the tree the host serves.","commonSituations":"Running an old schematic or generator (pre-v6 style) in a modern CLI workspace where the config is 'angular.json' not '.angular.json'; running schematics outside a real Angular workspace (no config file at all); tools that build a virtual Tree programmatically and forgot to stub the workspace config.","solutions":["Run the schematic inside a directory containing a valid Angular workspace config ('angular.json' / '.angular.json') created via 'ng new' or 'ng generate config'.","If you maintain the schematic, migrate to '@schematics/angular/utility/workspace' (readWorkspace) instead of the legacy 'utility/config' getWorkspace shim.","If constructing a Tree programmatically, add a workspace config: host.create('/.angular.json', Buffer.from(JSON.stringify(workspace))) or '/angular.json' depending on the host lookup.","Upgrade the CLI/schematic package versions so both sides agree on the config file name."],"exampleFix":"// before (legacy schematic)\nimport { getWorkspace } from '@schematics/angular/utility/config';\nconst workspace = getWorkspace(tree);\n\n// after\nimport { workspaces } from '@angular-devkit/core';\nimport { createWorkspaceHost } from '@angular-devkit/architect/node';\nconst { workspace } = await workspaces.readWorkspace('/', createWorkspaceHost(tree));","handlingStrategy":"validation","validationCode":"import { Tree } from '@angular-devkit/schematics';\nfunction hasWorkspaceConfig(host: Tree): boolean {\n  return host.exists('/angular.json') || host.exists('/.angular.json');\n}\nif (!hasWorkspaceConfig(tree)) {\n  throw new Error('Not inside an Angular workspace: no angular.json found');\n}","typeGuard":"function isWorkspaceTree(host: Tree): host is Tree & { __hasWorkspace: true } {\n  return (host as Tree).exists('/angular.json') || (host as Tree).exists('/.angular.json');\n}","tryCatchPattern":"try {\n  const workspace = getWorkspace(tree);\n} catch (e) {\n  if (e instanceof SchematicsException && /Could not find \\(/.test(e.message)) {\n    // fall back to modern readWorkspace or abort with a friendly message\n  } else { throw e; }\n}","preventionTips":["Always run schematics from a directory that contains angular.json (check with 'ls angular.json' or CLI cwd detection).","Use the modern workspaces.readWorkspace API instead of the legacy utility/config shim.","When building Trees in tests, always stub the workspace config file.","Keep CLI and @schematics/angular versions in sync."],"tags":["angular-cli","schematics","workspace-config","angular-json"],"backgroundTag":"workspace-config-not-found","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}