Trouble loading ZipReader from locally saved script #486
-
Hi, I'm having trouble getting a small test page to work. I strongly suspect it's purely down to my inexperience in modern JS rather than a problem with zip.js, but I'm at my wit's end with it, so any help would be massively appreciated. This is just a small html page with zip-full.min.js stored in a 'lib' subfolder. It should read a zip and output the blob to the console, then do the same for the contents. The first part works, but the second doesn't:
Line 21 is where the problem is, it cannot read the 'ZipReader' class and throws an error. I get the same with zip.min.js too, although I'm not sure I understand the difference. Is there anything silly I'm missing? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You have to call Alternatively, you can add at the top of your code: const { ZipReader, BlobReader, BlobWriter } = zip;
... |
Beta Was this translation helpful? Give feedback.
-
Thanks, had a feeling it would be something basic like that! |
Beta Was this translation helpful? Give feedback.
You have to call
new zip.ZipReader(new zip.BlobReader(zipFileInput.files[0]))
instead ofnew ZipReader(new BlobReader(zipFileInput.files[0]))
(andnew zip.BlobWriter()
as well) because you're not using zip.js as an ECMAScript Module (i.e. ESM).Alternatively, you can add at the top of your code: