0

I'm trying to hook up jszip to my Flask/python project running in VS on windows, but JS crashes as soon as I try to import jszip or declare an instance with the 'var JSZip = require("jszip");' call. I've tried both downloading and extracting the zip installer as well as installing with npm. Npm installs with success and node is in the path. The npm seem to create a folder within the 'static' called 'node_modules\jszip' while i've unzipped the one I downloaded to 'scripts\jszip'. When I either add the 'import' declaration or the 'var JSZip = require("jszip");' line, the js function crashes. Same if I only call the top folder 'import JSZip from 'node_modules/jszip'. Without the 'import' nor the 'require' call, the Alert displays. I'm a new to js modules, so it's probably a very basic error but I just cannot spot it. Any help appreciated :-)

import JSZip from 'node_modules/jszip/dist/jszip.js';

function download_zip(arrUrls) {
    alert("1");
    var JSZip = require("jszip");
}
davidism
  • 121,510
  • 29
  • 395
  • 339
user123442
  • 29
  • 6
  • It's a flask browser application. – user123442 Apr 10 '22 at 11:18
  • Have you tried this? https://stackoverflow.com/a/45968868/3761628 – eol Apr 10 '22 at 11:27
  • Yes. the npm init creates a package.json file in the static folder that looks like this: { "dependencies": { "file-saver": "^2.0.5", "jszip": "^3.9.1", "jszip-utils": "^0.1.0" }, "name": "static", "version": "1.0.0", "main": "index.js", "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "description": "" } and this is my script includer: – user123442 Apr 10 '22 at 12:14
  • I regret that my question has been closed because the provided answer, how to serve static files in Flask did not solve my problem with jszip. (I'm already successfully serving both the js file that contains my posted little 'download_zip' function, which works if I remove the 'import' and 'require' lines as well as other static files like bstreeview like that). So my problem is the 'import' and 'require' lines. – user123442 Apr 10 '22 at 13:14

0 Answers0