MSW fails to import when running unit tests in browser mode

Open
#32,523 10 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
angular, typescript

Research direction

Start by reproducing the listed Angular 21 browser-mode unit-test setup with Vitest and an import from msw; then inspect how the Angular unit test runner passes resolve conditions. Done means the browser-mode tests can import msw without the entry-point externalization error, while the jsdom behavior remains unchanged.

Written by the indexing model from the issue text.

Description

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

Dominant language
TypeScript
Stars
27k
Forks
11.8k
Avg merge
16h 35m
Merged PRs (30d)
176

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from angular/angular-cli

All issues in angular/angular-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.