MSW fails to import when running unit tests in browser mode
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- angular, typescript
- 领域
- build-system, testing
调研方向
首先,使用 Vitest 以及从 msw 的导入,复现所列出的 Angular 21 浏览器模式单元测试设置;然后检查 Angular 单元测试运行器如何传递 resolve conditions。完成的标准是:浏览器模式测试可以导入 msw,且不会出现入口点外部化错误,同时 jsdom 的行为保持不变。
由索引模型根据 Issue 内容生成。
描述
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
mswin 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
- 主要语言
- TypeScript
- 星标
- 27k
- 派生
- 11.8k
- 平均合并
- 16 小时 21 分钟
- 30 天内合并 PR
- 170
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
angular/angular-cli 的其他 Issue
-
area: @angular/build gemini-triaged
难度 2/5 1-3 小时 新手友好度 76/100
angular/angular-cli#34129 ·
-
area: @angular/cli gemini-triaged
难度 2/5 1-3 小时 新手友好度 84/100
angular/angular-cli#34057 ·
-
area: @angular/build gemini-triaged
难度 2/5 1-3 小时 新手友好度 74/100
angular/angular-cli#33955 ·
-
area: @angular/cli gemini-triaged
难度 2/5 1-3 小时 新手友好度 72/100
angular/angular-cli#33055 · 1 条评论 · 3 个 reaction ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34131 · 已指派 1 人 ·