menu

Questions & Answers

Using JSZip in an Angular library

I am developing multiple websites in angular with similar content and have therefore decided to extract common components and functionality into a separate angular 13 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: (jszip__WEBPACK_IMPORTED_MODULE_1___namespace_cache || jszip__WEBPACK_IMPORTED_MODULE_1___namespace_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?

Comments:
2023-01-19 11:42:02
I have same problem, did you find the solution?
2023-01-19 11:42:02
@Lupe sadly not yet. Temporarily I have decided not to zip the files but that proved to be both anoying and bad, since the browser refused to let me download ~30 files at once and let just the first ~10 trough. I am currently looking into this again, but I am most likely going to look for alternatives to jszip
2023-01-19 11:42:02
@Lupe I have thrown jszip out and replaced it with client-zip advertised by its author here stackoverflow.com/a/63738976/15893674. This works without any issues. It is not a complete substitue of jszip however, depending on what you want to use it for.
Answers(1) :

I'm also facing same issue. It's working with Angular 12 but getting same error as above mentioned with Angular 14.

ERROR TypeError: (jszip__WEBPACK_IMPORTED_MODULE_1___namespace_cache || jszip__WEBPACK_IMPORTED_MODULE_1___namespace_cache) is not a constructorcode here