`@angular/build:unit-test` with Vitest test runner throws `Failed to import test file` error
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 52/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Stack tecnológico
- angular, typescript
- Área
- build-system, testing
Línea de trabajo
Comienza revisando el manejo de providersFile del runner @angular/build:unit-test y el init-testbed.js generado; después reproduce el fallo usando el repositorio mínimo enlazado. Verifica la corrección ejecutando ng test con TestService inyectando Router y confirmando que todas las specs se importan y pasan sin el error del compilador JIT.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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 │
└───────────────────────────┴───────────────────┴───────────────────┘
- Lenguaje dominante
- TypeScript
- Estrellas
- 27k
- Forks
- 11.8k
- Merge medio
- 16 h 21 min
- PR fusionados (30 d)
- 170
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de angular/angular-cli
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-server Abiertoarea: @angular/build gemini-triaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
angular/angular-cli#33955 ·
-
area: @angular/cli gemini-triaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
angular/angular-cli#33055 · 1 comentario · 3 reacciones ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34131 · 1 asignado ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34130 · 1 asignado ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34128 · 1 asignado ·
Todos los issues de angular/angular-cli
Issues similares
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
-
Ecosystem: ClawMetry — the Qwen Code reader is now free and open source (follow-up to #9294 / #9338) Abiertocategory/integration priority/P3 scope/documentation status/ready-for-human type/feature-request
Dificultad 1/5 Menos de una hora Aptitud para principiantes 84/100
-
area:auth FE mvp P3
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
klasolsson81/jobbliggaren#1788 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
get-convex/migrations#69 ·
-
accessibility angular bug good first issue typescript ux
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
apache/fineract-backoffice-ui#584 · 1 comentario ·