rndme/download

Add support for ESM browser import

Opened this issue · 9 comments

It seems the library cannot be loaded with module imports on modern browsers.

The purpose would be to allow such imports since JavaScript imports are now available with all major browsers. Including an esm file or adapting existing files in the NPM package to have a default or another export would allow something like the following:

import downloadjs from 'downloadjs';
Kepro commented

it's working for long time, did you test it?

@Kepro Here is a quick example to test with Chrome:

https://glitch.com/edit/#!/descriptive-shelf?path=index.html:2:76

ESM imports are not supported. The packaged version does not contain an ESM compatible version so I wonder how it can work. If you have a working example I would be happy to see it.

Kepro commented

@lpellegr use it as import downloadjs from 'downloadjs'; I'm using that library for years in my ES6 project

It is not working with module imports (see the updated example). Are you sure you don't have a packaging step in your working project? The issue is about raw import using ES6 module imports.

Kepro commented

I don't know, I'm using normal webpack with babel (and currently with typescript) and both are working well

This is working in your case because you are using Typescript. The code is then transpiled for AMD/UMD, commonJS exports. There are cases where having ES6 modules imports working from scratch is useful, especially since modern browsers now have native support for such imports.

Kepro commented

using native support is still risky, only few % of users have latest versions, but I got your point

It depends on the use case. For instance, with Polymer 3 you can create multiple bundles that are compatible with all browsers but your source code needs to use module imports to have tree shaking working efficiently.

Kepro commented

@lpellegr , maybe is time to ask developer of downloadjs-next ( https://github.com/huy-nguyen/download ) as this repo is not more updated...