eligrey / eligrey/FileSaver.js

Cannot dynamic import FileSaver.js

Open
#758 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
22k
Forks
4.3k
PR merge metrics
No merged PRs in 30d

Description

## What's wrong?
It gets error when import `FileSaver` dynamically
```javascript
(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");
})();
```

![](https://github.com/mirusu400/FileSaver-Issue/raw/main/2022-05-21-19-28-19.png)

## Temporary solution
Just remove or make comment 11st line.

```javascript
(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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.