Skip to content
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

pdfjs-dist dependancy issue for setIterator #1164

Open
simandi434 opened this issue Dec 5, 2024 · 18 comments · May be fixed by #1161
Open

pdfjs-dist dependancy issue for setIterator #1164

simandi434 opened this issue Dec 5, 2024 · 18 comments · May be fixed by #1161

Comments

@simandi434
Copy link

Hi,

I have updated my ng2-pdf-viewer version to the latest which is (10.4.0 and also tried with 10.3.4) but still I see the pdfjs-dist dependency issue.

Issue is listed below. please check.

Error: node_modules/pdfjs-dist/types/web/pdf_viewer.d.ts:175:26 - error TS2552: Cannot find name 'SetIterator'. Did you mean 'Iterator'?

image

And below are my project dev dependencies.

"devDependencies": {
"@angular-devkit/build-angular": "^18.0.7",
"@angular/cli": "^18.0.7",
"@angular/compiler-cli": "~18.0.6",
"@types/file-saver": "^2.0.5",
"@types/jasmine": "~3.10.0",
"@types/node": "^12.11.1",
"chromium": "~3.0.3",
"husky": "^9.0.11",
"jasmine-core": "~3.10.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.1.0",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"karma-junit-reporter": "~2.0.1",
"prettier": "^3.2.5",
"pretty-quick": "^4.0.0",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "^5.4.5"
}

@shamoon
Copy link
Contributor

shamoon commented Dec 5, 2024

See #1137 (comment) --> #1161 (unless another solution is found)

@shamoon shamoon linked a pull request Dec 5, 2024 that will close this issue
@simandi434
Copy link
Author

simandi434 commented Dec 5, 2024

@shamoon Updating angular to next Major version will leads to lot of complexities. Are you planning something that will be done from this module side.

@vkbiotech841
Copy link

I am also using facing the above issue. tried installling child dependency (pdfjs-dist) separately as well. This is a typescript problem. Angular 18 does not support typescript version 5.6.3. Whereas "SetIterator" type has been introduced in Typescript version 5.6.0 onward. Even downgrading ng2-pdf-veiwer should have been solved this issue. But looks like that library has been modified in such a way that it does not work for previous version as well.

This is my requrest please fix this ASAP. we facing this problem.

The only we are left with is upgrading Angular version to 19. I have tested this in angular version 19 where typescript version 5.6.3 is supported. It is working. but there are warning messages as well.

The above dynamic import cannot be analyzed by Vite.
See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.

Plugin: vite:import-analysis
File: /vite/deps/ng2-pdf-viewer.js?v=a9a70d24
4:35:50 PM [vite] warning:
/vite/deps/ng2-pdf-viewer.js
26462| const sandbox = import(
26463| /webpackIgnore: true/
26464| sandboxBundleSrc
| ^^^^^^^^^^^^^^^^
26465| );
26466| sandbox.then((pdfjsSandbox) => {
The above dynamic import cannot be analyzed by Vite.
See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.

Plugin: vite:import-analysis
File: /.angular/cache/19.0.2/klearstack-ui/vite/deps/ng2-pdf-viewer.js?v=a9a70d24

@shamoon
Copy link
Contributor

shamoon commented Dec 5, 2024

  1. To clarify, this plugin can still be installed in Angular < 19, you'll just need to specify version 10.3.4. The only 'downside' is a slightly older version of pdfjs.
  2. The vite error warning is present in all current versions and is a separate issue. It's also just a warning.

@shamoon
Copy link
Contributor

shamoon commented Dec 6, 2024

In the meantime, there is this workaround: mozilla/pdf.js#18867 (comment)

  1. Add e.g. "typings": "./src/typings.d.ts" to your package.json file
  2. Create the file src/typings.d.ts containing only: type SetIterator = Iterator;

@vkbiotech841
Copy link

vkbiotech841 commented Dec 6, 2024

@shamoon #1161 also does not work.

Showing error:

Duplicate identifier 'SetIterator'.ts(2300)
lib.es2015.iterable.d.ts(192, 11): 'SetIterator' was also declared here.

@shamoon
Copy link
Contributor

shamoon commented Dec 6, 2024

What doesn't work, the PR or the workaround? The workaround would only work (and be needed) in a project with ts < 5.6. Certainly both worked in my testing...

The error you just reported suggests you're building with a version of typescript that has it already

@vkbiotech841
Copy link

vkbiotech841 commented Dec 6, 2024

@shamoon both PR and workaround did not work:

My configurations are as follows:

angular 18
typescript: 5.5.4
ng2-pdf-viewer: 10.3.4

the workaround error message is :

Duplicate identifier 'SetIterator'.ts(2300)
lib.es2015.iterable.d.ts(192, 11): 'SetIterator' was also declared here.

@shamoon
Copy link
Contributor

shamoon commented Dec 6, 2024

Even downgrading ng2-pdf-veiwer should have been solved this issue. But looks like that library has been modified in such a way that it does not work for previous version as well.

Also, this just isn't true. Your comments lead me to believe your packages are messed up (either the lock file or just the node_modules and you're not doing a clean install). But this note is not possible, older versions of plugins dont get modified somehow, that's literally the point of npm.

@vkbiotech841
Copy link

@shamoon after your messasge. I have deleted the package.lock.json file as well it did not work.

Error is same SetIterator" type problem.

Regarding node_module, yes I have removed it completly and even removed or clean the its caches as well.

Yes, my previoous message does not sounds logical for version downgrade but its happing.

@shamoon
Copy link
Contributor

shamoon commented Dec 6, 2024

A Stackblitz: https://stackblitz.com/edit/stackblitz-starters-pqzeyp
Also: mozilla/pdf.js#18867 (comment)
Screenshot 2024-12-05 at 11 19 23 PM
Screenshot 2024-12-05 at 11 19 35 PM

@adityasahusentra
Copy link

I am facing this issue too, it's so weird. I have angular v18.2.0 and I don't want to upgrade to v19.
Typescript says it is already declared but can't find it, how can that be? What did I do wrong?

✘ [ERROR] TS2552: Cannot find name 'SetIterator'. Did you mean 'Iterator'? [plugin angular-compiler]

node_modules/ng2-pdf-viewer/node_modules/pdfjs-dist/types/web/pdf_viewer.d.ts:175:25:
  175 │     [Symbol.iterator](): SetIterator<any>;
      ╵                          ~~~~~~~~~~~

image

@sleepycodernotes
Copy link

sleepycodernotes commented Dec 10, 2024

I am facing this issue too, it's so weird. I have angular v18.2.0 and I don't want to upgrade to v19. Typescript says it is already declared but can't find it, how can that be? What did I do wrong?

✘ [ERROR] TS2552: Cannot find name 'SetIterator'. Did you mean 'Iterator'? [plugin angular-compiler]

node_modules/ng2-pdf-viewer/node_modules/pdfjs-dist/types/web/pdf_viewer.d.ts:175:25:
  175 │     [Symbol.iterator](): SetIterator<any>;
      ╵                          ~~~~~~~~~~~

image

Funny use this lib in production.. xDDD use "ng2-pdf-viewer": "10.2.2", "pdfjs-dist": "4.2.67", "typescript": "~5.4.5",

@andreasdorfer
Copy link

Angular 17.3.0
Typescript: 5.2.2
ng2-pdf-viewer: 10.4.0

I saw the same issue with SetIterator.
Fixed it by adding "./typings.d.ts" in tsconfig.app.json -> include array.

// typings.d.ts:
type SetIterator = Iterator;

@shamoon
Copy link
Contributor

shamoon commented Dec 11, 2024

Angular 17.3.0 Typescript: 5.2.2 ng2-pdf-viewer: 10.4.0

I saw the same issue with SetIterator. Fixed it by adding "./typings.d.ts" in tsconfig.app.json

That is what I said above... #1164 (comment) --> mozilla/pdf.js#18867 (comment)

  1. Add e.g. "typings": "./src/typings.d.ts" to your package.json file
  2. Create the file src/typings.d.ts containing only: type SetIterator = Iterator;

@jhancd10
Copy link

Angular 17.3.0 Typescript: 5.2.2 ng2-pdf-viewer: 10.4.0

I saw the same issue with SetIterator. Fixed it by adding "./typings.d.ts" in tsconfig.app.json -> include array.

// typings.d.ts: type SetIterator = Iterator;

Now it's working! Thanks!!!

@andreasdorfer
Copy link

That is what I said above... #1164 (comment) --> mozilla/pdf.js#18867 (comment)

  1. Add e.g. "typings": "./src/typings.d.ts" to your package.json file
    Adding it to package.json didn't work for me.

@simandi434
Copy link
Author

The issue is solved with adding typings.d.ts. Thanks @shamoon for the quick help. But please let un know here once the issue is fixed form the module dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants