question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ngcc modifies node_module making it no longer work in a web worker

See original GitHub issue

Bug Report

Affected Package

This issue is caused by ngcc (as far as I can tell)

Is this a regression?

Yes, this previously used to work. I’m not sure exactly what version broke it but, I had this working in angular 10 (or a very early version of angular 11).

Description

It appears ngcc is modifying files within node_modules/@datorama/akita/lib. The modificaitons add @angular/core as an import in store.d.ts (among a few other lines of code). Once this occurs I am no longer able to build the app if a web worker imports the @datorama/akita package as @angular/core requires the dom library which is not available in a web worker.

Minimal Reproduction

I have a reproduction here: https://stackblitz.com/edit/angular-ivy-wvs54l However, stackblitz doesn’t seem to support webworkers. So, you need to download the project and then perform:

npm i
npm run ng build

Essentially all you need to do is create an angular app

  • Add the @datorama/akita npm package
  • Add a webworker
  • Instantiate the webworker in the angular app
  • In the webworker import the @datorama/akita package

Once you have done this any attempt to build the app will fail.

Exception or Error


Error: ./src/app/web-workers/test.worker.ts (./node_modules/worker-plugin/dist/loader.js?name=0!./src/app/web-workers/test.worker.ts)
Module build failed (from ./node_modules/worker-plugin/dist/loader.js):
Error: node_modules/@angular/core/core.d.ts:10411:62 - error TS2304: Cannot find name 'Element'.

10411 export declare function ɵgetDebugNode__POST_R3__(nativeNode: Element): DebugElement__POST_R3__;

There are more errors that follow which all are basically due to the dom library not being available in a web worker.

Your Environment

Angular Version:


Angular CLI: 11.2.13
Node: 14.16.0
OS: win32 x64

Angular: 11.2.13
... animations, cli, common, compiler, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1102.13
@angular-devkit/build-angular   0.1102.13
@angular-devkit/core            7.3.10
@angular-devkit/schematics      7.3.10
@angular/compiler-cli           11.2.14
@schematics/angular             11.2.13
@schematics/update              0.1102.13
rxjs                            6.6.7
typescript                      4.0.7

Anything else relevant?

So, I don’t really know how ngcc works but, what I do know is that I end up with 2 files in @datorama/akita/lib

  • store.d.ts
  • store.d.ts.__ivy_ngcc_bak

If I replace store.ts with store.d.ts.__ivy_ngcc_bak I can now build successfully.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
petebacondarwincommented, May 18, 2021

The longer term problem is that, while it is ngcc that is adding the typing dependency, there is still an implicit dependency between Aikita and Angular because the Store is marked as an Angular directive. So even moving on to the new partial compiled Ivy library distribution will not solve the problem.

0reactions
angular-automatic-lock-bot[bot]commented, Jun 19, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 9 - NGCC fails with an unhandled exception
This problem (NGCC failed) was encountered by me and my colleague developer on our localhost machines. It would be important to remark that ......
Read more >
Use web workers to run JavaScript off the browser's main thread
The browser's main thread is incredibly overworked. By using web workers to shift code off the main thread, you can significantly improve ...
Read more >
How to execute a function with a web worker on a different ...
With web workers, we are able to execute a script in a background thread and leave the main thread free for UI work....
Read more >
Running Web Worker in Angular 6 Application - Medium
Run some of CPU intensive business logic in a web worker thread. Angular has provided support for approach #1 in the framework itself....
Read more >
Introduction to Web Workers in JavaScript - Listen and Send ...
Parallel programming allows applications to run different computations at the same time. An example of how humans benefit from doing tasks in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found