eligrey / FileSaver.js

An HTML5 saveAs() FileSaver implementation
https://eligrey.com/blog/saving-generated-files-on-the-client-side/
Other
21.58k stars 4.38k forks source link

Cannot dynamic import FileSaver.js #758

Open mirusu400 opened 2 years ago

mirusu400 commented 2 years ago

What's wrong?

It gets error when import FileSaver dynamically

(async() => {
    const FileSaverSrc = "./FileSaver.js";
    const FileSaverLib = await import(FileSaverSrc);
    var blob = new Blob(["Hello, world!"], { type: "text/plain;charset=utf-8" });
    saveAs(blob, "hello world.txt");
})();

Temporary solution

Just remove or make comment 11st line.

(function (global, factory) {
  if (typeof define === "function" && define.amd) {
    define([], factory);
  } else if (typeof exports !== "undefined") {
    factory();
  } else {
    var mod = {
      exports: {}
    };
    factory();
    // global.FileSaver = mod.exports; <- remove this line !!
  }
})(this, function () {

Test repo

Here is my test repo. https://github.com/mirusu400/FileSaver-Issue