kennethjiang / js-file-download

MIT License
918 stars 119 forks source link

ES6 import not working #67

Closed roti closed 4 years ago

roti commented 4 years ago

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);
kalibano commented 4 years ago

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

kindrowboat commented 4 years ago

@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?

kindrowboat commented 4 years ago

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