ng2-pdf-viewer icon indicating copy to clipboard operation
ng2-pdf-viewer copied to clipboard

Cannot find name 'WeakKey'. version 10.2.2

Open diveshdobal opened this issue 1 year ago • 14 comments

Bug Report or Feature Request (mark with an x)
- [ ] Regression (a behavior that used to work and stopped working in a new release)
- [ ] Bug report -> please search issues before submitting
- [ ] Feature request
- [ ] Documentation issue or request

After updating from 9.1.5 to 10.2.2 I got error - Error: node_modules/pdfjs-dist/types/web/text_layer_builder.d.ts:41:32 - error TS2304: Cannot find name 'WeakKey'.

41 textDivProperties: WeakMap<WeakKey, any>;

My angular version 16.2.12

diveshdobal avatar May 30 '24 11:05 diveshdobal

any update on this, I got the same issue after updating to latest version for security update

Adhikaripr avatar May 31 '24 23:05 Adhikaripr

Same here...need to update this package but can't because of this error.

evo-ksalter avatar Jun 03 '24 14:06 evo-ksalter

I have the exact same problem. Any help appreciated.

mibadim avatar Jun 05 '24 12:06 mibadim

using below libraries for viewing pdf in my application, but throwing below error. "ng2-pdf-viewer": "^10.2.1", "pdfjs-dist": "^4.3.136"

------------------------------------Error------------------------------------------------------------------------------------------------ Error: node_modules/ng2-pdf-viewer/node_modules/pdfjs-dist/types/web/text_layer_builder.d.ts:41:32 - error TS2304: Cannot find name 'WeakKey'.

text_layer_builder.d.ts file : line number 41 :textDivProperties: WeakMap<WeakKey, any>;


** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

SurekhaKarthik avatar Jun 06 '24 17:06 SurekhaKarthik

Same problem here, in my case, using angular 16.2.12 :

  • error appears in every version since 10.1.0
  • used many ng2-pdf-viewer and pdfjs-dist version combinations does not seem to work either

The only solution that i have found to use it with angular 16 is downgrade to 10.0.0 and remove pdfjs-dist from package.json

mgustran avatar Jun 12 '24 16:06 mgustran

On an angular 16 project, try adding;

"skipLibCheck": true,

to your tsconfig.json file.

This has fixed the issue for me on my angular 16 project.

On my Angular 17 project I found this was not necessary.

I noticed in this commit https://github.com/VadimDez/ng2-pdf-viewer/commit/15cba0d603dcaec52f27cbdb89e97d3ef7cec0f6 that the same was added to this project.

JRobinsIken avatar Jun 13 '24 12:06 JRobinsIken

Same here.

BUT you do not want to disable the lib checking. pdfjs-dist anyway has a lot of problems, npm complains abut a high severity issue in it for a long time. It would be best to get rid of that dependency altogether in this project.

pkunszt avatar Jun 28 '24 11:06 pkunszt

Same problem here

guiaume avatar Aug 19 '24 15:08 guiaume

Same here.

BUT you do not want to disable the lib checking. pdfjs-dist anyway has a lot of problems, npm complains abut a high severity issue in it for a long time. It would be best to get rid of that dependency altogether in this project.

Why is disabling lib checking not a good idea? Can you provide some context? I'm having this same error and have been looking for a solution for a while. I can make it work if I edit the affected line and change "WeakMap" for "any", but I have no idea what this could be breaking. And besides, it seems to not be a very practical solution because I would need to do this edit every time I do an npm install from scratch.

tutiplain avatar Aug 23 '24 13:08 tutiplain

@mgustran provided the most accurate answer. Using the 'skipLibCheck' option didn't seem like the right approach. I found it more effective to downgrade the version, remove pdfjs-dist, and that resolved the issue.

stalinmazac avatar Aug 29 '24 17:08 stalinmazac

Upgrading to Angular 17 solved it for me.

tutiplain avatar Aug 29 '24 17:08 tutiplain

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 26 '25 00:04 stale[bot]

Image

export declare const reverseTransformCache: WeakMap<WeakKey, any>;

i also got this error and i just change WeakKey type to any and it is working but it needs to resolve because i need to manually update this line when i do npm install.

Mohib-rexon-software avatar May 08 '25 06:05 Mohib-rexon-software

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 18 '25 23:07 stale[bot]