`ng generate component/directive --module` declares a class that doesn't exist when `addTypeToClassName` is `false`
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- angular, typescript
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- TypeScript
- スター
- 27k
- フォーク
- 11.8k
- 平均マージ
- 1日 6時間
- マージ済み PR(30日)
- 216
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
angular/angular-cli のほかの issue
-
area: @angular/build gemini-triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
angular/angular-cli#33955 ·
メンテナーはふだん 1 日以内に返信
-
area: @angular/cli gemini-triaged
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
angular/angular-cli#33055 · コメント 1 件 · リアクション 3 件 ·
メンテナーはふだん 1 日以内に返信
-
@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-111771対応中かも @florimond-collette が今日担当しました。 オープンarea: @angular/cli
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
angular/angular-cli#34455 ·
メンテナーはふだん 1 日以内に返信
-
@angular/build 22.2.x, 21.2.x and 20.3.x depend on [email protected] / [email protected] which are vulnerable to CVE-2026-112943対応中かも @florimond-collette が今日担当しました。 オープンarea: @angular/build
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
angular/angular-cli#34452 ·
メンテナーはふだん 1 日以内に返信
-
`ng generate app-shell` and `ng generate module --route` produce broken imports when a component `type` is configured対応中かも @MeAkib が 1 日前に担当しました。 オープンarea: @schematics/angular
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
angular/angular-cli#34449 ·
メンテナーはふだん 1 日以内に返信
angular/angular-cli の issue をすべて見る
似ている issue
-
[BUG] rag: sentence content can cross the reported sentence boundaries対応中かも @LJK-ikun が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
README: the Resource URI Schemas example's file://documents/* pattern only matches that literal URIオープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
platformatic/mcp#361 ·
メンテナーはふだん 1 日以内に返信
-
frontend
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Push: sem service worker ou sem VAPID, o interruptor de Notificações fica ligado sem avisar nadaオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
melgarafael/DeskcommCRM#3164 ·
メンテナーはふだん 1 日以内に返信