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

Works fine locally but can't get past new JSZip() instance when deployed on server #890

Open
mplatt212 opened this issue Feb 15, 2023 · 3 comments

Comments

@mplatt212
Copy link

I have a React JS project that incorporates JSZip and everything is great when I run it locally. But when it gets deployed to the server for whatever reason the click handler it resides inside of cannot make it past const zip = new JSZip() and I see the following error in the console:
image
I am importing the module at the top of the page as : import JSZip from 'jszip' and it is running 3.10.1. Any help is appreciated.`

@MERVE5412
Copy link

Merve sen bir kerede dafa dosya sil ya siz nekadar alçak pis karakterli insanlara8niz

@jhonman681
Copy link

Hi @mplatt212, I had the same issue, I fixed it by using dynamic imports like this:

const JSZip = await import('jszip/dist/jszip');
// because JSZip it is a module, .default is required
const jsZip = new JSZip.default(); // this line replace const zip = new JSZip();

do not forget to remove the import JSZip from 'jszip';

hope this helps you as well, 👍

@onassar
Copy link

onassar commented Jan 17, 2024

Adding in a comment here with specific keywords that would have saved me a bunch of time :)

The comment from @jhonman681 really helped. The context for me was:
I was upgrading an AWS lambda function from node 14 (node.js 14) to node 20 (node.js 20). I use JSZip for zipping up files, and naturally the old require('jszip') didn't work. This is what ended up working for me:

import * as JSZip from '/opt/node_modules/jszip/lib/index.js';

Then when I wanted to instantiate the object, I used:

var zip = JSZip.default();

Furthermore, I was doing this via an AWS Lambda Layer, and using jszip v3.10.1 (3.10.1).

Hope this saves someone else a bit of time :)

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

No branches or pull requests

4 participants