`@angular/build:unit-test` with Vitest test runner throws `Failed to import test file` error
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 52/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Ruhig
- Tech-Stack
- angular, typescript
- Bereich
- build-system, testing
Rechercherichtung
Beginne mit der providersFile-Behandlung des @angular/build:unit-test-Runners und der generierten init-testbed.js und reproduziere dann den Fehler mit dem verlinkten Minimal-Repository. Überprüfe den Fix, indem du ng test mit TestService ausführst, der Router injiziert, und bestätigst, dass alle Specs ohne den JIT-Compilerfehler importiert werden und erfolgreich durchlaufen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
No response
Description
Steps to reproduce:
- Create a
TestServicethat will contain a single propertyrouter = inject(Router) - Configure
@angular/build:unit-testrunner to includeprovidersFile - Export
[TestService]from it - Create a
Testcomponent that will inject this service:service = inject(TestService)
ng test will fail with the following error for all specs:
FAIL project (chromium) path/to/some.spec.ts [ path/to/some.spec.ts ]
Error: Failed to import test file /project/root/init-testbed.js
Caused by: Error: The injectable '_PlatformLocation' needs to be compiled using the JIT compiler, but '@angular/compiler' is not available.
The injectable is part of a library that has been partially compiled.
However, the Angular Linker has not processed the library such that JIT compilation is used as fallback.
Ideally, the library is processed using the Angular Linker to become fully AOT compiled.
Alternatively, the JIT compiler should be loaded by bootstrapping using '@angular/platform-browser-dynamic' or '@angular/platform-server',
or manually provide the compiler with 'import "@angular/compiler";' before bootstrapping.
❯ <static_initializer> node_modules/.vite/vitest/dc540563f7f56f2cac74b38788615874d1da1c10/deps/chunk-42LDSDVL.js?v=049c4943:83:17
If you remove injection of the TestService from the Test component all the specs will start to pass.
Minimal Reproduction
https://github.com/th0r/ng-vitest-test-providers-bug
Your Environment
Angular CLI : 21.0.1
Angular : 21.0.2
Node.js : 24.8.0
Package Manager : npm 11.6.0
Operating System : darwin arm64
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build │ 21.0.1 │ ^21.0.1 │
│ @angular/cli │ 21.0.1 │ ^21.0.1 │
│ @angular/common │ 21.0.2 │ ^21.0.0 │
│ @angular/compiler │ 21.0.2 │ ^21.0.0 │
│ @angular/compiler-cli │ 21.0.2 │ ^21.0.0 │
│ @angular/core │ 21.0.2 │ ^21.0.0 │
│ @angular/forms │ 21.0.2 │ ^21.0.0 │
│ @angular/platform-browser │ 21.0.2 │ ^21.0.0 │
│ @angular/router │ 21.0.2 │ ^21.0.0 │
│ rxjs │ 7.8.2 │ ~7.8.0 │
│ typescript │ 5.9.3 │ ~5.9.2 │
│ vitest │ 4.0.14 │ ^4.0.8 │
└───────────────────────────┴───────────────────┴───────────────────┘
- Vorherrschende Sprache
- TypeScript
- Sterne
- 27k
- Forks
- 11.8k
- Ø Merge
- 16 Std. 35 Min.
- Gemergte PRs (30 T.)
- 176
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus angular/angular-cli
-
area: @angular/build gemini-triaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
angular/angular-cli#33955 ·
-
area: @angular/cli gemini-triaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
angular/angular-cli#33055 · 1 Kommentar · 3 Reaktionen ·
-
unit-test: with --coverage, a setup file's hooks reach only the first spec file of each worker Offenarea: @angular/build gemini-triaged
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 72/100
angular/angular-cli#34137 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34131 · 1 zugewiesene Person ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34130 · 1 zugewiesene Person ·
Alle Issues in angular/angular-cli
Ähnliche Issues
-
S: triage
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
-
fix(errors): EHOSTUNREACH from a happy-eyeballs connect is reported as a resolver error (STAMP-80) Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
snapshot-labs/stamp#666 ·
-
fix(api): prevent leaderboard SSE heartbeat from starting after disconnect during initial load Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
GauravKarakoti/SecureFlow#1070 · 1 Kommentar ·
-
feature:Languages/Translations good first issue ready Web
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
digitalfabrik/integreat-app#4394 ·