WebWorkers problem in Angular related to Vite `optimizeDeps`
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 42/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Ruhig
- Tech-Stack
- typescript, vite
- Bereich
- build-system, tooling
Rechercherichtung
Klone die verlinkte cornerstonejs/angular-cornerstone3d-Reproduktion und führe npm i gefolgt von npm run start aus; vergleiche deren Angular-Setup mit den funktionierenden Vite-Beispielen. Untersuche, wie Angular CLI mit Vite optimizeDeps, Caching und Modul-Workern umgeht, und überprüfe anschließend, dass die Warnung behoben ist, der Worker den korrekten Pfad verwendet und npm run build erfolgreich ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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)
- Vorherrschende Sprache
- TypeScript
- Sterne
- 27k
- Forks
- 11.8k
- Ø Merge
- 16 Std. 35 Min.
- Gemergte PRs (30 T.)
- 176
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus angular/angular-cli
-
area: @angular/build gemini-triaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
angular/angular-cli#33955 ·
-
area: @angular/cli gemini-triaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
angular/angular-cli#33055 · 1 Kommentar · 3 Reaktionen ·
-
unit-test: with --coverage, a setup file's hooks reach only the first spec file of each worker Offenarea: @angular/build gemini-triaged
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 72/100
angular/angular-cli#34137 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34131 · 1 zugewiesene Person ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34130 · 1 zugewiesene Person ·
Alle Issues in angular/angular-cli
Ähnliche Issues
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
dennys-bd/agent-hive#184 ·
-
Add: hunch Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
AbdelStark/awesome-typesafe#104 ·
-
ai-observability bug team/ai-observability
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
vicharanashala/fln#563 ·