WebWorkers problem in Angular related to Vite `optimizeDeps`

Đang mở
#28,994 23 bình luận 24 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
typescript, vite
Lĩnh vực
build-system, tooling

Hướng nghiên cứu

Clone bản reproduction được liên kết của cornerstonejs/angular-cornerstone3d và chạy npm i, sau đó là npm run start; so sánh thiết lập Angular của bản này với các ví dụ Vite đang hoạt động. Điều tra cách Angular CLI xử lý Vite optimizeDeps, bộ nhớ đệm và module worker, sau đó xác minh rằng cảnh báo đã được giải quyết, worker sử dụng đúng đường dẫn và npm run build chạy thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

angular/build:application area: @angular/build freq1: low severity3: broken type: bug/fix
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:

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.

Image
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.

Image

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)

Image

Ngôn ngữ chính
TypeScript
Star
27k
Fork
11.8k
Merge trung bình
16 giờ 35 phút
Pull request đã merge (30 ngày)
176

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của angular/angular-cli

Tất cả issue của angular/angular-cli

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.