6

I was trying JSZip on NodeJS to create some ZIP file but i'm facing an issue.

I'm using the code proposed by JSZip :

var JSZip = require('JSZip')
var zip = new JSZip()
zip.file("Hello.txt", "Hello World\n")
zip.generateAsync({type:"blob"}).then(function(content) {
    //do things here
});

Currently the code throw an error on generateAsync

UnhandledPromiseRejectionWarning: Error: blob is not supported by this platform

Did something need to be install or the data I set in zip.file should be in a certain format ?

3
  • Possible duplicate of Node.js can´t create Blobs? Commented Jun 13, 2019 at 15:30
  • 1
    This topic does not seems to be useful in my case because I'm not trying to create a Blob but trying to create a ZIP from files. If you can precise how it can help me :) Thanks Commented Jun 13, 2019 at 15:45
  • There is a github issue on the exact same problem. It has been wrongfully closed. Commented Jun 13, 2019 at 16:22

1 Answer 1

13

JSZip throws this error at jszip/lib/utils.js:352:15 because of the value of support.blob, defined by at jszip/lib/support.js (lines 11 to 32). I don't know for your machine, but while trying to run this script in NodeJS, I've debugged it to the conclusion that JSZip detects blobs to be not supported because self is not defined, so line 23 throws an error and support.blob is set to false.

JSZip seems to support the Node Buffer type on Node though - the following doesn't throw any errors on my machine:

// JSZip v3.2.1
// NodeJS v8.10.0
// Ubuntu 18.04
const JSZip = require('jszip');

const zip = new JSZip();
zip.file('hello.txt', 'Hello world\n');
zip
    .generateAsync({type: 'nodebuffer'}) // blob -> nodebuffer
    .then(console.log);
Sign up to request clarification or add additional context in comments.

1 Comment

nodebuffer YES!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.