`ng generate component/directive --module` declares a class that doesn't exist when `addTypeToClassName` is `false`
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 25/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Estagnada
- Stack de tecnologia
- angular, typescript
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- TypeScript
- Estrelas
- 27k
- Forks
- 11.8k
- Merge médio
- 1d 6h
- PRs com merge (30d)
- 216
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de angular/angular-cli
-
area: @angular/build gemini-triaged
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
angular/angular-cli#33955 ·
Mantenedores costumam responder em até 1 dia
-
area: @angular/cli gemini-triaged
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
angular/angular-cli#33055 · 1 comentário · 3 reações ·
Mantenedores costumam responder em até 1 dia
-
@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-111771Talvez já em andamento @florimond-collette assumiu há 1 dia. Abertaarea: @angular/cli
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 35/100
angular/angular-cli#34455 ·
Mantenedores costumam responder em até 1 dia
-
@angular/build 22.2.x, 21.2.x and 20.3.x depend on [email protected] / [email protected] which are vulnerable to CVE-2026-112943Talvez já em andamento @florimond-collette assumiu há 1 dia. Abertaarea: @angular/build
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 25/100
angular/angular-cli#34452 ·
Mantenedores costumam responder em até 1 dia
-
`ng generate app-shell` and `ng generate module --route` produce broken imports when a component `type` is configuredTalvez já em andamento @MeAkib assumiu há 1 dia. Abertaarea: @schematics/angular
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
angular/angular-cli#34449 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de angular/angular-cli
Issues semelhantes
-
agent/scanner help wanted hive/claimed-by-scanner kind/bug stage/020-claimed
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 90/100
hivecommons/rationguard#315 ·
Mantenedores costumam responder em até 1 dia
-
agent-ready area: ui-sdk priority: p3 type: chore
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
schlessera/brain-kit#2534 ·
Mantenedores costumam responder em até 1 dia
-
bug lane:gh-5
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
LLM-4-People/bridlewise-testing#122 ·
Mantenedores costumam responder em até 1 dia
-
bug priority: P2
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
-
enhancement priority:low ready-for-dev
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 67/100
Mantenedores costumam responder em até 1 dia