gildas-lormeau / zip.js

JavaScript library to zip and unzip files supporting multi-core compression, compression streams, zip64, split files and encryption.
https://gildas-lormeau.github.io/zip.js
BSD 3-Clause "New" or "Revised" License
3.38k stars 510 forks source link

Cannot get library with "fetch()" #363

Closed eissar closed 2 years ago

eissar commented 2 years ago

I may be unfamiliar with js/deno, but I am getting an error message trying to import the module with "fetch()" i get the following error message from the browser console, using Firefox: " Uncaught (in promise) SyntaxError: import declarations may only appear at top level of a module " it seems like the Deno hosting blocks requests made with the browser "fetch()" by default. https://deno.land/manual@v1.25.1/examples/fetch_data

0f-0b commented 2 years ago

How exactly are you importing a module with fetch? The typical way to import other modules from a module is import declarations. For example:

<script type="module">
  import * as zip from "https://deno.land/x/zipjs@v2.6.23/index.js";
  console.log(zip);
</script>

To import a module from a classic script or inside a function, import calls can be used instead:

<script>
  import("https://deno.land/x/zipjs@v2.6.23/index.js").then((zip) => {
    console.log(zip);
  });
</script>
eissar commented 2 years ago

thank you. I am going to try another method. I was using: " eval(await (await fetch('https://cdn.jsdelivr.net/npm/archiver@5.3.1')).text()); " but people online are saying eval seems to be a big security risk so I will try loading modules with userscripts. this is for testing a browser extension on random webpages, so I was using the browser console. it worked with another library, so I guess this one has the security configured differently?

eissar commented 2 years ago

using a userscript with: // @require https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js works 👍

gildas-lormeau commented 2 years ago

If you still want to use zip.js (and get it from jsdelivr.net), I guess that will work too.

// @require https://cdn.jsdelivr.net/gh/gildas-lormeau/zip.js@2.6.23/dist/zip.min.js

Or

// @require https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.6.23/dist/zip.min.js
eissar commented 1 year ago

If you still want to use zip.js (and get it from jsdelivr.net), I guess that will work too.

sorry, I put the link in for a test with a different URL to see if the issue was with the CDN or something. I ended up using zip.js and it's working normally