MSW fails to import when running unit tests in browser mode

Aperta
#32,523 10 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
angular, typescript

Direzione di ricerca

Inizia riproducendo la configurazione indicata dei test unitari di Angular 21 in modalità browser con Vitest e un import da msw; quindi esamina come il runner dei test unitari di Angular passa le condizioni di risoluzione. Il lavoro è completato quando i test in modalità browser possono importare msw senza l’errore di esternalizzazione dell’entry point, mentre il comportamento di jsdom rimane invariato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

needs: investigation
Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

Yes

Description

In Angular 21, when running unit tests using the below configuration the run fails with "The entry point "msw" cannot be marked as external"

Setup:

  1. Create a new angular project.
  2. Set unit tests to use the chromium browser
  3. Install MSW
  4. Attempt to import anything from msw in a test case, the above error is thrown.

This appears to be related to a disconnect between the package.json configuration of MSW and the "resolve conditions" that are being passed to Vitest by the angular unit test runner.

When running the tests in jsdom (not browser) we do not encounter this issue.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

Please provide the environment you discovered this bug in (run ng version)
Angular CLI       : 21.1.4
Angular           : 21.1.5
Node.js           : 22.18.0
Package Manager   : npm 11.5.2
Operating System  : win32 x64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 21.1.4            │ ^21.1.4           │
│ @angular/cli              │ 21.1.4            │ ^21.1.4           │
│ @angular/common           │ 21.1.5            │ ^21.1.0           │
│ @angular/compiler         │ 21.1.5            │ ^21.1.0           │
│ @angular/compiler-cli     │ 21.1.5            │ ^21.1.0           │
│ @angular/core             │ 21.1.5            │ ^21.1.0           │
│ @angular/forms            │ 21.1.5            │ ^21.1.0           │
│ @angular/platform-browser │ 21.1.5            │ ^21.1.0           │
│ @angular/router           │ 21.1.5            │ ^21.1.0           │
│ rxjs                      │ 7.8.2             │ ~7.8.0            │
│ typescript                │ 5.9.3             │ ~5.9.2            │
│ vitest                    │ 4.0.18            │ ^4.0.8            │
└───────────────────────────┴───────────────────┴───────────────────┘
Anything else?

No response

Lingua principale
TypeScript
Stelle
27k
Fork
11.8k
Merge medio
16h 21m
PR unite (30g)
170

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di angular/angular-cli

Tutte le issue di angular/angular-cli

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.