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.

New EventSystem in v7 is conflicting with zone.js in Angular projects

See original GitHub issue

Expected Behavior

I should be able to use PixiJS in an Angular Project

Current Behavior

I get the following error when importing pixi.js v7.0.0 in an Angular projet:

Error: node_modules/@pixi/events/lib/FederatedEventTarget.d.ts:11:18 - error TS2320: Interface 'FederatedEventTarget' cannot simultaneously extend types 'EventEmitter<string | symbol, any>' and 'EventTarget'.
  Named property 'removeAllListeners' of types 'EventEmitter<string | symbol, any>' and 'EventTarget' are not identical.

11 export interface FederatedEventTarget extends utils.EventEmitter, EventTarget {
                    ~~~~~~~~~~~~~~~~~~~~

It turns out zone.js is monkey patching the native EventTarget interface (https://github.com/angular/angular/blob/37ba6104498202b671f5a5a6bbfacc4df501788b/packages/zone.js/lib/zone.api.extensions.ts#L29) to add a removeAllListeners?(eventName?: string): void; method, which conflicts with the removeAllListeners(event?: EventEmitter.EventNames<EventTypes>): this; method on the EventEmitter from the eventemitter3 package.

In an Angular projects (or any project using zone.js), it’s impossible to create an interface that extends EventEmitter (from eventemitter3) and EventTarget at the same time.

It’s possible to disable the monkey patch by adding this line to the Angular project (window as ZoneGlobalConfigurations).__Zone_disable_EventTarget = true; but the typing would still make the compilation fail.

Possible Solution

Still searching for one, does the FederatedEventTarget interface need to extend the EventTarget ?

Right now I can bypass the problem by not using the new EventSystem. So I have to avoid importing pixi.js or @pixi/events and only import the other packages individually (@pixi/core, @pixi/sprite, …)

Steps to Reproduce

  • Create an angular project
  • Install pixi.js
  • Import pixi.js or @pixi/events somewhere
  • Serve the project

Here is a reproduction repository: https://github.com/Julien-Marcou/angular-pixijs-issue-8794

Environment

  • pixi.js version: 7.0.0
  • angular version: 14.2.8
  • zone.js version: 0.11.8

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
bigtimebuddycommented, Oct 30, 2022

Feel free to make a PR. Also, the change should include a note about why we’re re-declaring a looser type here.

0reactions
Julien-Marcoucommented, Nov 1, 2022

It’s not masking other EventEmitter conflicts as it’s only overriding the signature for FederatedEventTarget which is already working with a string | symbol event emitter.

Here is what we get right now: image

And here is what we would get if we implement the fix: image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top 18 Most Common AngularJS Developer Mistakes
Common Mistake #16: Not Running The Unit Tests In TDD Mode​​ Tests will not make your code free of AngularJS error messages. What...
Read more >
NgZone
A zone is an execution context that persists across async tasks. You can think of it as thread-local storage for the JavaScript VM....
Read more >
How can i overcome 'Error: Zone already loaded' conflicts ...
If anyone can shed any light on this, that would be much appreciated. Running: Angular @ 2.4.0 zone.js @ 0.7.7. Thanks! javascript ·...
Read more >
cannot set properties of undefined (setting 'username')
import { Component, VERSION, ViewChild } from '@angular/core'; import { FormBuilder, FormControl, FormGroup, Validators, } from '@angular/forms'; ...
Read more >
Unity - Scripting API:
The rotation is often provided as a Euler angle and not a Quat. ... Sets the path that Unity should store the current...
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