`ng generate app-shell` and `ng generate module --route` produce broken imports when a component `type` is configured
维护者通常 1 天内回复
评估
- 难度
- 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 内容生成。
描述
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.
- 主要语言
- TypeScript
- 星标
- 27k
- 派生
- 11.8k
- 平均合并
- 1 天 6 小时
- 30 天内合并 PR
- 224
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 个 reaction ·
维护者通常 1 天内回复
-
area: @angular/ssr
难度 4/5 3-5 天 新手友好度 53/100
angular/angular-cli#34474 ·
维护者通常 1 天内回复
-
Tailwind CSS v4 classes in new or moved files are not picked up by ng serve until another rebuild可能已有人在做 @MeAkib 于 2 天前认领。 未关闭area: @angular/build
难度 4/5 3-5 天 新手友好度 35/100
angular/angular-cli#34446 ·
维护者通常 1 天内回复
-
unit-test builder (Vitest): key `fsModuleCache` on the served build output instead of forcing it off可能已有人在做 @jv3n 于 2 天前认领。 未关闭area: @angular/build
难度 4/5 3-5 天 新手友好度 20/100
angular/angular-cli#34443 ·
维护者通常 1 天内回复
查看 angular/angular-cli 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 68/100
cursor/community-plugins#465 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
vetro-protocol/vetro-monorepo#978 ·
维护者通常 1 天内回复
-
ai-generated bug category:security effort:s priority:p3
难度 2/5 1-3 小时 新手友好度 67/100
LanternOps/breeze#9697 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
maniator/verticopolis#1303 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 73/100
components-web-app/docs#297 ·