pdfjs-dist dependancy issue for setIterator
Opened this issue ยท 18 comments
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'?
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"
}
See #1137 (comment) --> #1161 (unless another solution is found)
@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.
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
- 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. - The vite error warning is present in all current versions and is a separate issue. It's also just a warning.
In the meantime, there is this workaround: mozilla/pdf.js#18867 (comment)
- Add e.g. "typings": "./src/typings.d.ts" to your package.json file
- Create the file src/typings.d.ts containing only: type SetIterator = Iterator;
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
@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.
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.
@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.
A Stackblitz: https://stackblitz.com/edit/stackblitz-starters-pqzeyp
Also: mozilla/pdf.js#18867 (comment)
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>;
โต ~~~~~~~~~~~
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>; โต ~~~~~~~~~~~
Funny use this lib in production.. xDDD use "ng2-pdf-viewer": "10.2.2", "pdfjs-dist": "4.2.67", "typescript": "~5.4.5",
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;
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)
- Add e.g. "typings": "./src/typings.d.ts" to your package.json file
- Create the file src/typings.d.ts containing only: type SetIterator = Iterator;
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!!!
That is what I said above... #1164 (comment) --> mozilla/pdf.js#18867 (comment)
- Add e.g. "typings": "./src/typings.d.ts" to your package.json file
Adding it to package.json didn't work for me.
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.