MSW fails to import when running unit tests in browser mode
- Ngôn ngữ chính
- TypeScript
- Star
- 27k
- Fork
- 11.8k
- Merge trung bình
- 14 giờ 23 phút
- Pull request đã merge (30 ngày)
- 162
Mô tả
### 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
```true
```
### Please provide the environment you discovered this bug in (run `ng version`)
```true
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_
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện thiết lập unit test ở chế độ trình duyệt của Angular 21 được liệt kê, sử dụng Vitest và một import từ `msw`; sau đó kiểm tra cách Angular unit test runner truyền các điều kiện resolve. Hoàn thành khi các test ở chế độ trình duyệt có thể import `msw` mà không gặp lỗi externalization entry-point, trong khi hành vi của jsdom vẫn không thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- angular, typescript
- Lĩnh vực
- build-system, testing
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100