Skip to content

Component schematic generates files without '.component' suffix (Angular CLI 21.1.3) #32451

@GonzaloCriado

Description

@GonzaloCriado

Command

generate

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When generating components using ng generate component (or ng g c), the generated files are missing the .component suffix in both filenames and class names.

Expected behavior:

  • Files: test.component.ts, test.component.html, test.component.scss
  • Class name: TestComponent
  • Template/style URLs: ./test.component.html, ./test.component.scss

Actual behavior:

  • Files: test.ts, test.html, test.scss
  • Class name: Test
  • Template/style URLs: ./test.html, ./test.scss

Root cause identified:
In @schematics/angular/component/index.js (line ~40), the default value for options.type is set to an empty string:

options.type ??= '';  // Should be 'component'

This causes the template naming convention __name@dasherize__.__type@dasherize__.ts to resolve to name..ts which collapses to name.ts.

Minimal Reproduction

  1. Create a new Angular project:
   ng new test-project --routing=false --style=scss
   cd test-project
  1. Generate a component:
   ng generate component test
  1. Observe the generated files in src/app/test/:

    • ❌ Generated: test.ts, test.html, test.scss, test.spec.ts
    • ✅ Expected: test.component.ts, test.component.html, test.component.scss, test.component.spec.ts
  2. Check the class name in test.ts:

    • ❌ Generated: export class Test
    • ✅ Expected: export class TestComponent

Workaround:
Explicitly specify the type: ng g c test --type=component


---

**Exception or Error:**

No exception thrown. The command executes successfully but generates files with incorrect naming convention.


---

**Your Environment:**

Pega aquí la salida de ng version

Exception or Error


Your Environment

Angular CLI: 21.1.3
Node: 22.13.1
Package Manager: npm 10.9.2
OS: win32 x64

Anything else relevant?

  • Tested on Windows 10 with Node 22.13.1
  • Issue persists across multiple fresh installations
  • The bug exists in the official NPM package, not a local corruption
  • File located at: node_modules/@angular/cli/node_modules/@schematics/angular/component/index.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions