Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebWorkers problem in Angular related to Vite optimizeDeps #28994

Open
1 task
sedghi opened this issue Nov 28, 2024 · 3 comments
Open
1 task

WebWorkers problem in Angular related to Vite optimizeDeps #28994

sedghi opened this issue Nov 28, 2024 · 3 comments

Comments

@sedghi
Copy link

sedghi commented Nov 28, 2024

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

@sedghi sedghi changed the title WebWorkers problem in Angular with Vite related to optimizeDeps WebWorkers problem in Angular related to Vite optimizeDeps Nov 28, 2024
@daemon29
Copy link

@alan-agius4 could you please look into this bug?

@ssokmen
Copy link

ssokmen commented Dec 16, 2024

Hey @alan-agius4, have you had a chance to take a look? Many Angular users who utilize Cornerstone3D, an open-source medical imaging library, have encountered this issue. It’s a known challenge within the community, affecting developers working with Angular who aim to integrate Cornerstone3D for medical image viewing and manipulation. Because of that, this issue is blocking our progress.

@zhan2016
Copy link

@alan-agius4 could you please look into this bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants