Skip to content

Importing packages with workers: workers that import external packages fail silently when called #29574

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

Closed
1 task
varfoer opened this issue Feb 5, 2025 · 2 comments

Comments

@varfoer
Copy link

varfoer commented Feb 5, 2025

Command

serve, build

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

When a package contains a worker that is importing an external dependency in the worker script the worker will silently fail when called. An error event can be received when defining a callback for Worker.onerror but this isn't of much help. The issue only occurs with external dependencies (even if the dependency is unused). In the minimal reproduction example I am using comlink but the same happens when importing something from lodash. Importing local scripts is working fine though.
I have tried other major UI libraries like react, svelte and vue that have no problems with the any of the workers (despite the optimizeDeps issue with the vite bundler).

Problematic code:

import * as Comlink from 'comlink'; // even failing when not used further down

const obj = {
    test() {
        console.log("hello");
    }
}

onmessage = (message) => {
    console.log(message.data, "from worker with import");
}

Comlink.expose(obj);

Image

Loading the worker script had to be achieved by setting these settings in the angular.json:

      "architect": {
        "build": {
        ...
            "assets": [
              {
                "glob": "**/*",
                "input": "public"
              },
              {
                "glob": "**/*",
                "input": "node_modules/worker_package/dist"
              }
            ],
        ...
        "serve": {
          "options": {
            "prebundle": false
          },
         ...

Otherwise I would be stuck with this issue: #28994
I don't know if this would lead to the error condition I am experiencing.

Minimal Reproduction

I have created a repository for reproducing the problem: https://github.com/varfoer/comlink_worker_issues
The worker packages is already build there, so you can go ahead and try npm i and npm start or npm run dev in the several folders for the different UI libraries.

Exception or Error


Your Environment

Angular CLI: 19.1.5
Node: 22.12.0
Package Manager: npm 11.0.0
OS: linux x64

Angular: 19.1.4
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1901.5
@angular-devkit/build-angular   19.1.5
@angular-devkit/core            19.1.5
@angular-devkit/schematics      19.1.5
@angular/cli                    19.1.5
@schematics/angular             19.1.5
rxjs                            7.8.1
typescript                      5.7.3
zone.js                         0.15.0

Anything else relevant?

No response

@alan-agius4
Copy link
Collaborator

The error occurs because the worker itself is not bundled, causing it to import a non-existent module. Although the error message isn't very clear, it originates from the browser.

The root issue is being tracked in:

@alan-agius4 alan-agius4 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 6, 2025
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants