WebWorkers problem in Angular related to Vite `optimizeDeps`
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 42/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- typescript, vite
- 领域
- build-system, tooling
调研方向
克隆链接的 cornerstonejs/angular-cornerstone3d 复现项目,并依次运行 npm i 和 npm run start;将其 Angular 设置与正常工作的 Vite 示例进行比较。调查 Angular CLI 对 Vite optimizeDeps、缓存和模块 worker 的处理方式,然后验证警告已解决、worker 使用正确的路径,并且 npm run build 成功执行。
由索引模型根据 Issue 内容生成。
描述
Command
serve
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
We have a library that utilizes web workers. It employs the new Worker interface:
const instance = new Worker(
new URL('./decodeImageFrameWorker.js', import.meta.url),
{ type: 'module' }
);
We have successfully consumed the lib in various scenarios, whether based on Webpack or Vite. See the examples below:
- https://github.com/cornerstonejs/vite-react-cornerstone3d
- https://github.com/cornerstonejs/vue-cornerstone3d
- https://github.com/cornerstonejs/nextjs-cornerstone3d
When integrating into a Vite-based framework, a warning appears regarding one of the dependencies. This is a known issue in Vite, specifically with esbuild. To resolve this, we should add the library to optimizeDeps in the Vite config - recommended by vite maintainers, which works well.
I attempted to integrate a poc of the same library in Angular and encountered a similar warning. I tried customizing Vite but faced a limitation, as there is no way to override optimizeDeps in Angular, as noted here.
In some threads, I see that setting
"cli": {
"cache": {
"enabled": false
}
}
removes the warning above, but then the worker is requested from an incorrect path.
I also have tried the following
"development": {
"buildTarget": "angular-vite-6:build:development",
"prebundle": false
}
still no success
Minimal Reproduction
This is basically minimal repo for reproduction
commands to run
npm i
npm run start
Exception or Error
With the cache enabled, the Vite warning appears, and disabling the cache loads the worker from the wrong path.
Your Environment
Angular CLI: 19.0.2
Node: 18.19.1
Package Manager: npm 10.2.4
OS: darwin arm64
Angular: 19.0.1
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1900.2
@angular-devkit/build-angular 19.0.2
@angular-devkit/core 19.0.2
@angular-devkit/schematics 19.0.2
@angular/cli 19.0.2
@schematics/angular 19.0.2
rxjs 7.8.1
typescript 5.6.3
zone.js 0.15.0
Anything else relevant?
I want to emphasize that other Vite-based implementations for Vue, React, and Quasar work, so it's only Angular that's not working.
In addition, the npm run build also does not work and tries to load the worker from a wrong path (Again the build with vite, and webpack works)
- 主要语言
- TypeScript
- 星标
- 27k
- 派生
- 11.8k
- 平均合并
- 16 小时 35 分钟
- 30 天内合并 PR
- 176
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
angular/angular-cli 的其他 Issue
-
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 ·
-
area: @angular/build gemini-triaged
难度 4/5 3-5 天 新手友好度 72/100
angular/angular-cli#34137 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34131 · 已指派 1 人 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34130 · 已指派 1 人 ·
查看 angular/angular-cli 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
ontola/atomic-server#1625 ·
-
bug
难度 2/5 1-3 小时 新手友好度 70/100
melgarafael/DeskcommCRM#1451 ·
-
难度 1/5 1 小时以内 新手友好度 82/100
-
bug via-triage
难度 2/5 1-3 小时 新手友好度 78/100
-
bot:ai-assisted component:compact-js status:untriaged
难度 2/5 1-3 小时 新手友好度 84/100
midnightntwrk/midnight-sdk#403 ·