You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MSW fails to import when running unit tests in browser mode #32523
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:
Create a new angular project.
Set unit tests to use the chromium browser
Install MSW
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)
We are installing msw via npm and then importing from browser for setup. All the setup typs (such as HttpReponse, http, graphql etc) are only available by importing msw.
This used to work in angular 20 under the experimental UnitTest support
This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?
You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.
This might be related to your directory structure so its really important to get an accurate repro to diagnose this.
@alan-agius4 I was wondering if there were any other ideas on this.. We would gladly submit a PR to fix it if we had some direction on what might be the culprit.
FYI, this is still an issue on Angular 22. I can create a branch of the example repo with it in Angular 22 if you'd like, but all I did was run the update script on the existing repo.
Thanks, @lacolaco, I used your workaround successfully in my Angular 21 project (see vitest-base.config.ts): rkrisztian/contenttree@7d56ac5
(I'm going to delete my old branch soon.)
I'm not ready to upgrade yet due to certain dependencies that did not catch up with Angular 22 yet, so I'm glad this also works in Angular 21.
Activity
alan-agius4 commentedon Mar 5, 2026
@prowe, are you importing the browser variant of
msw?prowe commentedon Mar 5, 2026
We are installing
mswvia npm and then importing from browser for setup. All the setup typs (such as HttpReponse, http, graphql etc) are only available by importingmsw.This used to work in angular 20 under the experimental UnitTest support
alan-agius4 commentedon Mar 19, 2026
This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?
You can read here why this is needed. A good way to make a minimal repro is to create a new app via
ng new repro-appand adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.This might be related to your directory structure so its really important to get an accurate repro to diagnose this.
JamRenDoc commentedon Mar 20, 2026
https://github.com/JamRenDoc/angular-repro-32523
Here is a minimally viable project that reproduces this issue. You can see it when running the tests via 'npm run test'. Thanks!
alan-agius4 commentedon Mar 20, 2026
I am not seeing an msw usage in the reproduction.
JamRenDoc commentedon Mar 20, 2026
It's in the test. app.spec.ts.
prowe commentedon Apr 1, 2026
@alan-agius4 I was wondering if there were any other ideas on this.. We would gladly submit a PR to fix it if we had some direction on what might be the culprit.
jrdockendorff commentedon Jun 4, 2026
FYI, this is still an issue on Angular 22. I can create a branch of the example repo with it in Angular 22 if you'd like, but all I did was run the update script on the existing repo.
rkrisztian commentedon Jun 4, 2026
I followed the Vitest Browser Mode documentation on an Angular 21.2.15 project, and I'm getting the same issue.
Update: For reproducibility, this is not a minimal project, but here is my branch where I tried to integrate MSW:
refactor: Angular v22 へアップデート + city-search を Signal Forms 統合に再整理 (#50)
rkrisztian commentedon Jun 10, 2026
Thanks, @lacolaco, I used your workaround successfully in my Angular 21 project (see
vitest-base.config.ts):rkrisztian/contenttree@7d56ac5
(I'm going to delete my old branch soon.)
I'm not ready to upgrade yet due to certain dependencies that did not catch up with Angular 22 yet, so I'm glad this also works in Angular 21.