Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

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

Offen
#34,231 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
68/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
angular, typescript

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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            │
└───────────────────────────┴───────────────────┴───────────────────┘
Vorherrschende Sprache
TypeScript
Sterne
27k
Forks
11.8k
Ø Merge
1 T. 2 Min.
Gemergte PRs (30 T.)
168

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus angular/angular-cli

Alle Issues in angular/angular-cli

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.