`ng generate component/directive --module` declares a class that doesn't exist when `addTypeToClassName` is `false`
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 25/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- À l'abandon
- Stack technique
- angular, typescript
Piste de recherche
Start with packages/schematics/angular/utility/add-declaration-to-ng-module.ts and compare how the component and directive schematics compute class names in their index.ts files. Reproduce with the ng generate component widget --module app command and ng build; done means the NgModule declaration and export names match the generated class when addTypeToClassName is false. A linked pull request is already open.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
The addTypeToClassName option was added in 21.0.0, and the declaration code was not updated, so it never worked.
Description
When a component or directive is generated into an NgModule with addTypeToClassName: false and a type set, the
generated class and the symbol added to the NgModule don't match:
- The component/directive class is named without the type (e.g.
Widget), as configured. - The NgModule
declarations(andexportswith--export) import the name with the type
(e.g.WidgetComponent), so the build fails.
This is the configuration that ng new --no-standalone --file-name-style-guide=2016 writes to angular.json:
"@schematics/angular:component": { "type": "component", "addTypeToClassName": false },
"@schematics/angular:directive": { "type": "directive", "addTypeToClassName": false }
The component and directive schematics compute the class name with addTypeToClassName
(packages/schematics/angular/component/index.ts, packages/schematics/angular/directive/index.ts), but the shared
addDeclarationToNgModule helper always appends the type:
// packages/schematics/angular/utility/add-declaration-to-ng-module.ts
const classifiedName =
strings.classify(options.name) + (options.type ? strings.classify(options.type) : '');
Minimal Reproduction
ng new ws --no-standalone --file-name-style-guide=2016 --defaults
cd ws
ng generate component widget --module app
ng build
Generated src/app/widget/widget.component.ts:
export class Widget {}
Updated src/app/app.module.ts:
import { WidgetComponent } from './widget/widget.component';
@NgModule({
declarations: [App, WidgetComponent],
The same happens for ng generate directive ... --module.
Exception or Error
✘ [ERROR] TS2305: Module '"./widget/widget.component"' has no exported member 'WidgetComponent'. [plugin angular-compiler]
✘ [ERROR] NG1010: Value at position 1 in the NgModule.declarations of AppModule is not a reference
Your Environment
Angular CLI : 22.2.3
Node.js : 24.15.0
Package Manager : npm 11.12.1
Operating System : darwin arm64
@schematics/angular : 22.2.3
Anything else relevant?
- Introduced together with
addTypeToClassNamein e417c89f9e (#31053, v21.0.0). The same code is on21.2.xand22.2.x. - Suggested fix: let
addDeclarationToNgModuleuse the class name computed by the calling schematic (or honour
addTypeToClassName), so the declaration matches the generated class. Happy to send a PR with specs for the
component and directive schematics.
- Langage dominant
- TypeScript
- Étoiles
- 27k
- Forks
- 11.8k
- Merge moyen
- 1 j 6 h
- PR mergées (30 j)
- 216
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de angular/angular-cli
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-serverOuvertearea: @angular/build gemini-triaged
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
angular/angular-cli#33955 ·
Les mainteneurs répondent en général sous 1 jour
-
area: @angular/cli gemini-triaged
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
angular/angular-cli#33055 · 1 commentaire · 3 réactions ·
Les mainteneurs répondent en général sous 1 jour
-
@angular/cli 21.2.x and 20.3.x depend on @modelcontextprotocol/[email protected] which is vulnerable to CVE-2026-111767, CVE-2026-111768, CVE-2026-111769 and CVE-2026-111771Peut-être pris @florimond-collette l’a pris il y a 1 jour. Ouvertearea: @angular/cli
Difficulté 2/5 1-3 heures Accessibilité débutants 35/100
angular/angular-cli#34455 ·
Les mainteneurs répondent en général sous 1 jour
-
@angular/build 22.2.x, 21.2.x and 20.3.x depend on [email protected] / [email protected] which are vulnerable to CVE-2026-112943Peut-être pris @florimond-collette l’a pris il y a 1 jour. Ouvertearea: @angular/build
Difficulté 3/5 1-2 jours Accessibilité débutants 25/100
angular/angular-cli#34452 ·
Les mainteneurs répondent en général sous 1 jour
-
`ng generate app-shell` and `ng generate module --route` produce broken imports when a component `type` is configuredPeut-être pris @MeAkib l’a pris il y a 1 jour. Ouvertearea: @schematics/angular
Difficulté 3/5 1-2 jours Accessibilité débutants 35/100
angular/angular-cli#34449 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de angular/angular-cli
Issues similaires
-
agent/scanner help wanted hive/claimed-by-scanner kind/bug stage/020-claimed
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100
hivecommons/rationguard#315 ·
Les mainteneurs répondent en général sous 1 jour
-
agent-ready area: ui-sdk priority: p3 type: chore
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
schlessera/brain-kit#2534 ·
Les mainteneurs répondent en général sous 1 jour
-
bug lane:gh-5
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
LLM-4-People/bridlewise-testing#122 ·
Les mainteneurs répondent en général sous 1 jour
-
bug priority: P2
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
enhancement priority:low ready-for-dev
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
Les mainteneurs répondent en général sous 1 jour