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.

Cannot find name 'OffscreenCanvas' (inside an angular app)

See original GitHub issue

Hello, I have the same symptoms of this issue: https://github.com/pixijs/pixijs/issues/8174

But the problem isn’t fixed for me yet, and the solution there (installing @types/offscreencanvas) did not help either.

Expected Behavior

Angular app should start even after adding pixi.js.

Current Behavior

Starting the application gives the following error:


Error: node_modules/@pixi/core/index.d.ts:1534:45 - error TS2304: Cannot find name 'OffscreenCanvas'.

1534     static test(source: unknown): source is OffscreenCanvas | HTMLCanvasElement;
                                                 ~~~~~~~~~~~~~~~


Error: node_modules/@pixi/text/index.d.ts:306:105 - error TS2304: Cannot find name 'OffscreenCanvas'.

306     static measureText(text: string, style: TextStyle, wordWrap?: boolean, canvas?: HTMLCanvasElement | OffscreenCanvas): TextMetrics_2;
                                                                                                            ~~~~~~~~~~~~~~~


Error: node_modules/@pixi/text/index.d.ts:444:47 - error TS2304: Cannot find name 'OffscreenCanvas'.

444     static get _canvas(): HTMLCanvasElement | OffscreenCanvas;
                                                  ~~~~~~~~~~~~~~~


Error: node_modules/@pixi/text/index.d.ts:450:55 - error TS2304: Cannot find name 'OffscreenCanvasRenderingContext2D'.

450     static get _context(): CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;

Steps to Reproduce

  • create an angular app (ng new my-project)
  • npm install pixi.js
  • call new Application() on startup

It is reproduced here: https://github.com/kevincentius/angular-pixi-bug-reproduce

Running npm install and npm start should start the project and trigger the error

Environment

  • pixi.js 6.3.2
  • angular 13.3.0
  • Windows 10

Issue Analytics

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

github_iconTop GitHub Comments

6reactions
Crefeldercommented, May 31, 2022

Installed packages for pixijs and ng 13.3.7 version: image

TWO different ideas that are working for me: 1.

Add type offscreencanvas to tsconfig.app.json: image

Add allowSyntheticDefaultImports in compilerOptions in tsconfig.json image

OR 2.

In the src folder of angular I´ve added a empty file called typings.d.ts with this content: declare type OffscreenCanvas = any; declare type OffscreenCanvasRenderingContext2D = any; image

add this to tsconfig.json image

THEN

Add in angular.json image

For getting rid of this message: image I’ve added allowedCommonJsDependencies: - url image

if you have max size warnings you can change them in angular.json image

2reactions
kevincentiuscommented, May 13, 2022

I just tested and found pixi to work on Angular 12, but does not on Angular 13.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript Cannot find offscreencanvas - Stack Overflow
As per my comment to your question. This seems to be a TypeScript version problem, but the version in your package.json seems to...
Read more >
[Solved]-Typescript Cannot find offscreencanvas-three.js
This seems to be a TypeScript version problem, but the version in your package.json seems to be correct. Have you tried to run...
Read more >
OffscreenCanvas - Web APIs | MDN
Chrome Edge OffscreenCanvas Full support. Chrome69. Toggle history Full support. Edge79... OffscreenCanvas() constructor Full support. Chrome69. Toggle history Full support. Edge79... contextlost event Full support. Chrome99....
Read more >
TypeScript configuration - Angular
The Angular CLI generates a tsconfig.app.json file which is used to build an application, in which the types compiler option is set to...
Read more >
cannot find name offscreencanvas, error ts2304
Method 1: Checking if OffscreenCanvas exists: The typeof operator is used to return a string of the type of the operand. The OffscreenCanvas...
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