From b7b643d5500f35ac3988369ff2130bf669ae688c Mon Sep 17 00:00:00 2001 From: MeAkib Date: Wed, 21 Oct 2026 16:49:23 +0600 Subject: [PATCH 1/3] fix(@schematics/angular): set explicit type for the `module --route` component `ng generate module --route` generates a component and references it from the routing module template by its default file and class name (`./foo`, `Foo`). The component inherited the workspace `type` option, so in workspaces that set it (e.g. after updating to v20) the component was generated as `foo.component.ts` and the routing module import failed to resolve. Pass an empty `type`, as the library and app-shell schematics do. Fixes #34449 --- packages/schematics/angular/module/index.ts | 3 +++ .../schematics/angular/module/index_spec.ts | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/packages/schematics/angular/module/index.ts b/packages/schematics/angular/module/index.ts index adf0474a08a3..45acf616dd63 100644 --- a/packages/schematics/angular/module/index.ts +++ b/packages/schematics/angular/module/index.ts @@ -183,6 +183,9 @@ const moduleSchematic: RuleFactory = createProjectSchematic( path: options.path, project: options.project, standalone: false, + // The route templates reference the component by its default file and class name, so the + // component must not inherit a `type` from the workspace. + type: '', }; return chain([ diff --git a/packages/schematics/angular/module/index_spec.ts b/packages/schematics/angular/module/index_spec.ts index 8224f3642111..c9b364e69528 100644 --- a/packages/schematics/angular/module/index_spec.ts +++ b/packages/schematics/angular/module/index_spec.ts @@ -165,6 +165,28 @@ describe('Module Schematic', () => { ); }); + it('should not inherit the component `type` from the workspace defaults', async () => { + // The CLI applies the `schematics` defaults of `angular.json` to nested schematics as well. + // Emulate it with a fresh runner so that other tests are not affected. + const runner = new SchematicTestRunner( + '@schematics/angular', + require.resolve('../collection.json'), + ); + runner['_engineHost'].registerOptionsTransform( + (schematic: { name: string }, options: Record) => + schematic.name === 'component' && options['type'] === undefined + ? { ...options, type: 'component' } + : options, + ); + + const tree = await runner.runSchematic('module', options, appTree); + + expect(tree.exists('/projects/bar/src/app/foo/foo.ts')).toBe(true); + expect(tree.exists('/projects/bar/src/app/foo/foo.component.ts')).toBe(false); + const content = tree.readContent('/projects/bar/src/app/foo/foo-routing-module.ts'); + expect(content).toContain(`import { Foo } from './foo';`); + }); + it('should generate a lazy loaded module with embedded route declarations', async () => { appTree.overwrite( '/projects/bar/src/app/app-module.ts', From 61def7be81862afdeec22ec94a0d75dfc20ba37c Mon Sep 17 00:00:00 2001 From: MeAkib Date: Thu, 22 Oct 2026 08:06:57 +0600 Subject: [PATCH 2/3] fixup! fix(@schematics/angular): set explicit type for the `module --route` component --- .../schematics/angular/module/index_spec.ts | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/packages/schematics/angular/module/index_spec.ts b/packages/schematics/angular/module/index_spec.ts index c9b364e69528..8224f3642111 100644 --- a/packages/schematics/angular/module/index_spec.ts +++ b/packages/schematics/angular/module/index_spec.ts @@ -165,28 +165,6 @@ describe('Module Schematic', () => { ); }); - it('should not inherit the component `type` from the workspace defaults', async () => { - // The CLI applies the `schematics` defaults of `angular.json` to nested schematics as well. - // Emulate it with a fresh runner so that other tests are not affected. - const runner = new SchematicTestRunner( - '@schematics/angular', - require.resolve('../collection.json'), - ); - runner['_engineHost'].registerOptionsTransform( - (schematic: { name: string }, options: Record) => - schematic.name === 'component' && options['type'] === undefined - ? { ...options, type: 'component' } - : options, - ); - - const tree = await runner.runSchematic('module', options, appTree); - - expect(tree.exists('/projects/bar/src/app/foo/foo.ts')).toBe(true); - expect(tree.exists('/projects/bar/src/app/foo/foo.component.ts')).toBe(false); - const content = tree.readContent('/projects/bar/src/app/foo/foo-routing-module.ts'); - expect(content).toContain(`import { Foo } from './foo';`); - }); - it('should generate a lazy loaded module with embedded route declarations', async () => { appTree.overwrite( '/projects/bar/src/app/app-module.ts', From 15f0372d65327cad0ae2cda2f7d5c13e65f56154 Mon Sep 17 00:00:00 2001 From: MeAkib Date: Fri, 23 Oct 2026 23:17:15 +0600 Subject: [PATCH 3/3] fixup! fix(@schematics/angular): set explicit type for the `module --route` component --- packages/schematics/angular/module/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/schematics/angular/module/index.ts b/packages/schematics/angular/module/index.ts index 45acf616dd63..ce966eb0f778 100644 --- a/packages/schematics/angular/module/index.ts +++ b/packages/schematics/angular/module/index.ts @@ -184,8 +184,9 @@ const moduleSchematic: RuleFactory = createProjectSchematic( project: options.project, standalone: false, // The route templates reference the component by its default file and class name, so the - // component must not inherit a `type` from the workspace. + // component must not inherit a `type` or `exportDefault` from the workspace. type: '', + exportDefault: false, }; return chain([