ng test fails with NG8001 in a new NgModule app on 22.2.0
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 68/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- angular, typescript
调研方向
Reproduce the failure with the provided ng test command, then inspect the Vitest runner behavior described since #34134, starting with app.spec.ts, app-module.ts, and tsconfig.spec.json. Trace which files are compiled through imports and verify the generated NgModule app passes on 22.2.0 without adding an import workaround.
由索引模型根据 Issue 内容生成。
描述
Command
test
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
22.1.9
Description
In a new NgModule app, ng test fails on 22.2.0 with NG8001 for <router-outlet>. The same app generated with 22.1.9 passes.
Since #34134, the Vitest runner compiles the spec files, the setup and providers files, and the files they import. No spec imports app-module.ts, so it is not compiled, even though tsconfig.spec.json includes it.
Minimal Reproduction
npx @angular/[email protected] new repro --standalone=false --defaults
cd repro
npx ng test --watch=false
The generated app is not changed. src/app/app.html ends with <router-outlet />.
With @angular/[email protected], the same app passes (1 test file, 2 tests) when the @angular/* packages are pinned to ~22.1.0 before installing.
Adding import './app-module' at the top of src/app/app.spec.ts makes the tests pass on 22.2.0. Adding src/app/app-module.ts to files in tsconfig.spec.json does not.
Exception or Error
Application bundle generation failed. [1.373 seconds]
✘ [ERROR] NG8001: 'router-outlet' is not a known element:
1. If 'router-outlet' is an Angular component, then verify that it is part of this module.
2. If 'router-outlet' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. Find more at https://next.angular.dev/errors/NG8001 [plugin angular-compiler]
src/app/app.html:344:0:
344 │ <router-outlet />
╵ ~~~~~~~~~~~~~~~~~
Error occurs in the template of component App.
src/app/app.ts:7:15:
7 │ templateUrl: './app.html',
╵ ~~~~~~~~~~~~
Your Environment
Angular CLI : 22.2.0
Angular : 22.2.0
Node.js : 26.7.0
Package Manager : npm 11.19.0
Operating System : darwin arm64
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build │ 22.2.0 │ ^22.2.0 │
│ @angular/cli │ 22.2.0 │ ^22.2.0 │
│ @angular/common │ 22.2.0 │ ^22.2.0 │
│ @angular/compiler │ 22.2.0 │ ^22.2.0 │
│ @angular/compiler-cli │ 22.2.0 │ ^22.2.0 │
│ @angular/core │ 22.2.0 │ ^22.2.0 │
│ @angular/forms │ 22.2.0 │ ^22.2.0 │
│ @angular/platform-browser │ 22.2.0 │ ^22.2.0 │
│ @angular/router │ 22.2.0 │ ^22.2.0 │
│ rxjs │ 7.8.2 │ ~7.8.0 │
│ typescript │ 6.0.3 │ ~6.0.2 │
│ vitest │ 5.0.3 │ ^5.0.0 │
└───────────────────────────┴───────────────────┴───────────────────┘
- 主要语言
- TypeScript
- 星标
- 27k
- 派生
- 11.8k
- 平均合并
- 1 天 46 分钟
- 30 天内合并 PR
- 160
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
angular/angular-cli 的其他 Issue
-
area: @angular/cli
难度 1/5 1 小时以内 新手友好度 78/100
angular/angular-cli#34263 ·
维护者通常 1 天内回复
-
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 天内回复
-
Two TS linting errors in `main.ts`可能已有人在做 @Hangell 今天认领。 未关闭area: @schematics/angular
难度 1/5 1 小时以内 新手友好度 45/100
angular/angular-cli#34267 ·
维护者通常 1 天内回复
-
area: @angular/build
难度 4/5 3-5 天 新手友好度 48/100
angular/angular-cli#34262 ·
维护者通常 1 天内回复
查看 angular/angular-cli 的全部 Issue
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 88/100
Small-tailqwq/dsh-deep-whale#187 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
melgarafael/DeskcommCRM#2503 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
0x80/isolate-package#218 ·
-
bug via-triage
难度 2/5 1-3 小时 新手友好度 82/100
pingdotgg/t3code#16859 · 1 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复