{"record":{"id":"9712527d2b945d89","repo":"angular/angular-cli","slug":"unsupported-schematic-context-expected-a-filesyst","errorCode":null,"errorMessage":"Unsupported schematic context. Expected a FileSystemSchematicContext.","messagePattern":"Unsupported schematic context\\. Expected a FileSystemSchematicContext\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/schematics/tools/file-system-engine-host-base.ts","lineNumber":286,"sourceCode":"      ...partialDesc,\n      schema,\n      schemaJson,\n      name,\n      path,\n      factoryFn: resolvedRef.ref,\n      collection,\n    });\n  }\n\n  createSourceFromUrl(url: Url): Source | null {\n    switch (url.protocol) {\n      case null:\n      case 'file:':\n        return (context) => {\n          // Check if context has necessary FileSystemSchematicContext path property\n          const fileDescription = context.schematic.description as { path?: string };\n          if (fileDescription.path === undefined) {\n            throw new Error(\n              'Unsupported schematic context. Expected a FileSystemSchematicContext.',\n            );\n          }\n\n          // Resolve all file:///a/b/c/d from the schematic's own path, and not the current\n          // path.\n          const root = normalize(resolve(fileDescription.path, url.path || ''));\n\n          return new HostCreateTree(new virtualFs.ScopedHost(new NodeJsSyncHost(), root));\n        };\n    }\n\n    return null;\n  }\n\n  transformOptions<OptionT extends object, ResultT extends object>(\n    schematic: FileSystemSchematicDesc,\n    options: OptionT,","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/schematics/tools/file-system-engine-host-base.ts#L268-L304","documentation":"Thrown by the URL handler created in createSourceFromUrl when a `file:` (or empty) URL source runs with a context whose schematic description lacks a `path` property. File-based schematics resolve relative file URLs against the schematic's own directory, which is only known for a FileSystemSchematicContext.","triggerScenarios":"Calling engine.createSourceFromUrl(new Url('file:...')) (or null) and passing a context that is not a FileSystemSchematicContext — e.g. a plain object context or a context created by another engine — so `context.schematic.description.path` is undefined.","commonSituations":"Custom tooling that builds a SchematicContext manually instead of through the FileSystemEngineHost; invoking a file: source from a test with a stubbed context; mixing engine hosts (NodeModuleEngineHost context used with a file: source).","solutions":["Obtain the context from the same engine/host that runs the schematic (e.g. FileSystemEngineHost / SchematicTestRunner) so it is a FileSystemSchematicContext.","Ensure the executing schematic's description has `path` set (i.e. it was created by createSchematicDescription of the file-system host).","If you must use a custom context, use a non-file Url source instead."],"exampleFix":"// before\nconst context = { schematic: { description: { name: 'x' } } } as any;\nengine.createSourceFromUrl(new Url('file:./files'), context);\n// after (use a real context from the file-system engine)\nconst context = host.createContext({}); // FileSystemSchematicContext with description.path\nengine.createSourceFromUrl(new Url('file:./files'), context);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isFileSystemContext(ctx: unknown): ctx is FileSystemSchematicContext {\n  const d = (ctx as any)?.schematic?.description;\n  return !!d && typeof d.path === 'string' && d.path.length > 0;\n}\n\nif (!isFileSystemContext(context)) throw new Error('Expected FileSystemSchematicContext');","tryCatchPattern":"try {\n  const source = engine.createSourceFromUrl(new Url('file:./files'), context);\n} catch (e) {\n  if (String(e.message).includes('Unsupported schematic context')) {\n    throw new Error('Create the context via the FileSystemEngineHost, not manually');\n  }\n  throw e;\n}","preventionTips":["Always obtain SchematicContext objects from the same engine host that runs the schematic.","In tests use SchematicTestRunner / UnitTestTree rather than fabricating contexts.","Avoid casting arbitrary objects with `as any` into SchematicContext."],"tags":["schematics","context","type-mismatch"],"backgroundTag":"unsupported-schematic-context","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}