Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

`ng generate app-shell` and `ng generate module --route` produce broken imports when a component `type` is configured

未關閉
#34,449 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@MeAkib 已經在處理了。

開始於 2026年10月20日。

  • #34450 來自 @MeAkib —— 未關閉
  • #34472 來自 @MeAkib —— 未關閉

評估

難度
3/5
預估耗時
1-2 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
angular, typescript
領域
build-system, cli

研究方向

Read packages/schematics/angular/app-shell/index.ts and the routing and non-routing module templates named in the issue, then compare how the library schematic handled this in commit 661609e3e. Reproduce with the two commands in the issue using the described component type configurations. Done means both generated imports resolve and the builds succeed; an open pull request is already linked.

由索引模型根據 Issue 內容生成。

描述

area: @schematics/angular
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

19.x (before the v20 file naming change)

Description

ng generate app-shell and ng generate module <name> --route <path> --module <parent> generate a component and then
reference it with a hard-coded file path and class name. Both assume the v20+ defaults (no type in the file or class
name). When the workspace configures a component type, the component inherits it and the hard-coded references no
longer match, so the build fails.

Workspaces get a component type in two common ways:

  1. Every workspace updated to v20 with ng update: the migration that keeps the previous style guide behaviour
    (fdc6291dda) adds "@schematics/angular:component": { "type": "component" }.
  2. ng new --file-name-style-guide=2016, which adds { "type": "component", "addTypeToClassName": false }.

Hard-coded references:

  • packages/schematics/angular/app-shell/index.ts: withAppShell(AppShell) and
    insertImport(..., 'AppShell', './app-shell/app-shell').
  • packages/schematics/angular/module/files/.../__name@dasherize__-routing__typeSeparator__module.ts.template (and the
    non-routing module template for --route without a routing module): import { <%= classify(name) %> } from './<%= dasherize(name) %>';

The library schematic had the same problem (#26981) and was fixed in 661609e3e by passing an explicit type: '' to the
component schematic.

Minimal Reproduction

app-shell (updated-workspace configuration):

ng new ws --defaults
cd ws
# what `ng update` to v20 adds to angular.json under projects.ws.schematics:
#   "@schematics/angular:component": { "type": "component" }
ng generate app-shell
ng build

Generated src/app/app-shell/app-shell.component.ts contains export class AppShellComponent {}, but
src/app/app.config.server.ts contains:

import { AppShell } from './app-shell/app-shell';
...
provideServerRendering(withRoutes(serverRoutes), withAppShell(AppShell))

module --route (2016 file name style):

ng new ws --no-standalone --file-name-style-guide=2016 --defaults
cd ws
ng generate module feature --route feature --module app
ng build

Generated src/app/feature/feature-routing.module.ts:

import { Feature } from './feature'; // the file is feature.component.ts
Exception or Error
# app-shell
✘ [ERROR] TS2307: Cannot find module './app-shell/app-shell' or its corresponding type declarations. [plugin angular-compiler]
✘ [ERROR] Could not resolve "./app-shell/app-shell"

# module --route
✘ [ERROR] Could not resolve "./feature"
✘ [ERROR] TS2307: Cannot find module './feature' or its corresponding type declarations. [plugin angular-compiler]
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?
  • Affected since 20.0.0 (hard-coded names from 23fc8e1e17, "generate components without a .component
    extension/type"). Same code on 21.2.x and 22.2.x.
  • Suggested fix: follow 661609e3e and pass type: '' (and addTypeToClassName: false, so the class name stays
    AppShell/Feature) to the component schematic in app-shell and module, so the generated files always match
    the references. Happy to send a PR.
  • The module --route case with addTypeToClassName: false also hits #<issue for 01> (wrong NgModule declaration);
    link the two once filed.
主要語言
TypeScript
星號
27k
分支
11.8k
平均合併
1 天 6 小時
30 天內合併 PR
224

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

angular/angular-cli 的其他 Issue

查看 angular/angular-cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。