Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

ng test fails with NG8001 in a new NgModule app on 22.2.0

未关闭
#34,231 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃

调研方向

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 内容生成。

描述

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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

angular/angular-cli 的其他 Issue

查看 angular/angular-cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。