kennethjiang / js-file-download

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ES6 import not working

roti opened this issue · comments

When using js-file-download with an ES6 import it expects the default export to be in .default.
When importing like this:

import fileDownload from "js-file-download";

I get following error:

Uncaught (in promise) TypeError: js_file_download_1.default is not a function

This is probably some incompatibility between CommonJS and ES6 modules. There is a workaround, using the entire module as the function:

import * as fileDownload from "js-file-download";
...
fileDownload(response.data);

just add window.fileDownload = require('js-file-download') in app.js file and use it like fileDownload(fileLocation, filename);

@roti I'm not able to reproduce this in my projects. I use

import fileDownload from 'js-file-download'

without any errors. Are you using Babel or Typescript? Could you please put together a codepen or small repo that reproduces the problem?

Closing due to inactivity. Please feel free to open a new issue if this persists.