`ng generate app-shell` and `ng generate module --route` produce broken imports when a component `type` is configured
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- angular, typescript
- Lĩnh vực
- build-system, cli
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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:
- Every workspace updated to v20 with
ng update: the migration that keeps the previous style guide behaviour
(fdc6291dda) adds"@schematics/angular:component": { "type": "component" }. 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--routewithout 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 on21.2.xand22.2.x. - Suggested fix: follow 661609e3e and pass
type: ''(andaddTypeToClassName: false, so the class name stays
AppShell/Feature) to the component schematic inapp-shellandmodule, so the generated files always match
the references. Happy to send a PR. - The
module --routecase withaddTypeToClassName: falsealso hits #<issue for 01> (wrong NgModule declaration);
link the two once filed.
- Ngôn ngữ chính
- TypeScript
- Star
- 27k
- Fork
- 11.8k
- Merge trung bình
- 1 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 216
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của angular/angular-cli
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-serverĐang mởarea: @angular/build gemini-triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
angular/angular-cli#33955 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: @angular/cli gemini-triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
angular/angular-cli#33055 · 1 bình luận · 3 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
@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-111771Có thể đã có người làm @florimond-collette đã nhận 1 ngày trước. Đang mởarea: @angular/cli
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
angular/angular-cli#34455 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
@angular/build 22.2.x, 21.2.x and 20.3.x depend on [email protected] / [email protected] which are vulnerable to CVE-2026-112943Có thể đã có người làm @florimond-collette đã nhận 1 ngày trước. Đang mởarea: @angular/build
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
angular/angular-cli#34452 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`ng generate component/directive --module` declares a class that doesn't exist when `addTypeToClassName` is `false`Có thể đã có người làm @MeAkib đã nhận 1 ngày trước. Đang mởarea: @schematics/angular
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
angular/angular-cli#34447 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của angular/angular-cli
Issue tương tự
-
bug P3 UI/UX
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
StellarState/SS-backend#712 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: backend bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
snapotter-hq/SnapOtter#3473 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
gitroomhq/postiz-app#2304 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Resolve CI maintenance findingsĐang mởharlan-agent-ready-to-implement routine:ci-review
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
harlan-zw/unlighthouse#454 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày