Stuk / jszip

Create, read and edit .zip files with Javascript
https://stuk.github.io/jszip/
Other
9.77k stars 1.3k forks source link

Using JSZip in an Angular 14 library #885

Open SaiAnandPeketi-GIS opened 1 year ago

SaiAnandPeketi-GIS commented 1 year ago

I am developing multiple websites in angular with similar content and have therefore decided to extract common components and functionality into a separate angular 14 library.

I have previously successfully used the JSZip library in one of these websites, but have then decided to move this implementation into the library.

Even though the code did not change, it stopped working.

If I try to call the method that uses JSZip from the library it now throws the following TypeError

ERROR TypeError: (jszipWEBPACK_IMPORTED_MODULE1namespace_cache || jszipWEBPACK_IMPORTED_MODULE1namespace_cache) is not a constructor When I try to create a new JSZip instance like this

const zip = new JSZip(); Based on this question the problem might be in how I import the library. I do it like this

import * as JSZip from 'jszip'; And according to this question that is how it should be done.

Both the library and the website projects build correctly but throw this error at runtime, so I don't think it is a problem with dependencies.

Has someone encountered a similar problem before? What should I try to solve this?

SaiAnandPeketi-GIS commented 1 year ago

I'm done some workaround to make it work by lower the version to 3.7.1 and it's working fine.

123KsL commented 1 year ago

TS7016 in Angular 14.2.3: Could not find a declaration file for module 'jszip'. 'C:/work/Tekweld Machine Monitoring Frontend/Tekweld-Machine-Monitoring-Frontend/node_modules/jszip/dist/jszip.min.js' implicitly has an 'any' type. Installing npm install @types/jszip will not work