Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generateAsync doesn't work and there was no error #724

Closed
xiaoqiao112 opened this issue Nov 20, 2020 · 11 comments · Fixed by #742
Closed

generateAsync doesn't work and there was no error #724

xiaoqiao112 opened this issue Nov 20, 2020 · 11 comments · Fixed by #742

Comments

@xiaoqiao112
Copy link

generateAsync对20个图片进行打包压缩时,该方法没有执行,且没有报错

@dfelix
Copy link

dfelix commented Nov 28, 2020

same issue here on 3.5.0

@derickkemp
Copy link

I also had generateAsync die silently on me.

We're using Webpack 5.9.0 and had to downgrade JSZip to 3.2.0 to get it working.

@xiaoqiao112
Copy link
Author

I also had generateAsync die silently on me.

We're using Webpack 5.9.0 and had to downgrade JSZip to 3.2.0 to get it working.
you use 3.2.0 version fixed the problem?

@xiaoqiao112
Copy link
Author

same issue here on 3.5.0

这个库是对图片大小有限制吗

@derickkemp
Copy link

you use 3.2.0 version fixed the problem?

Yup using 3.2.0 fixed the issue for me

@boucaud
Copy link

boucaud commented Dec 8, 2020

Had the same issue. async won't resolve using the 3.5.0 version from npm. Fixed with 3.2.0.

@jahed
Copy link
Contributor

jahed commented Feb 6, 2021

I've been looking into this. 3.5.0 does work, but you have to change your imports to use jszip/dist/jszip.js (or min.js). However, TypeScript will complain as the type definitions aren't mapped there.

I have a feeling it's because of 617e3ce causing Webpack 5 to get something wrong in module resolution.

Update: Found a fix, I'll send a PR.

@jahed
Copy link
Contributor

jahed commented Feb 6, 2021

I've been looking into exactly why Webpack is hanging silently. One thing I noticed is that in Webpack 5, since it doesn't include polyfills and globals by default, people have to use the ProvidePlugin for globals like Buffer. However, JSZip uses the existence of Buffer for NodeJS support.

exports.nodebuffer = typeof Buffer !== "undefined";

This was likely already an issue before Webpack 5. The dist build removes Buffer using Browserify which is why it works. But in Webpack 5, it fails to resolve browser in the package.json and falls back to main (which is the fix #742 provides).

There's likely a switch somewhere that switches to a NodeJS stream that never emits events in a browser, causing a silent failure from this hanging promise.

function accumulate(helper, updateCallback) {
return new external.Promise(function (resolve, reject){
var dataArray = [];
var chunkType = helper._internalType,
resultType = helper._outputType,
mimeType = helper._mimeType;
helper
.on('data', function (data, meta) {
dataArray.push(data);
if(updateCallback) {
updateCallback(meta);
}
})
.on('error', function(err) {
dataArray = [];
reject(err);
})
.on('end', function (){
try {
var result = transformZipOutput(resultType, concat(chunkType, dataArray), mimeType);
resolve(result);
} catch (e) {
reject(e);
}
dataArray = [];
})
.resume();
});
}

Anyways, that's why it hangs without an error. Browsers should use the dist build (#742).

@Stuk
Copy link
Owner

Stuk commented Feb 9, 2021

Unfortunately my time is very limited at the moment so haven't been able to confirm this fix. However, I've published #742 as version 3.6.0-0 and if someone confirm that this fixes the issue for them I'd really appreciate it.

@MichaelFedora
Copy link

@Stuk can confirm it works now, was hanging before for me as well. Thanks!

@Stuk Stuk closed this as completed in #742 Feb 10, 2021
@Stuk
Copy link
Owner

Stuk commented Feb 10, 2021

@MichaelFedora thanks for checking! Fix published in 3.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants