ankane / chartkick

Create beautiful JavaScript charts with one line of Ruby
https://chartkick.com
MIT License
6.33k stars 565 forks source link

Provide ES module for JS with default exports #612

Closed dkniffin closed 1 year ago

dkniffin commented 1 year ago

I am trying to use this library via importmap, without global imports:

import Chartkick from "chartkick"

That way, I can avoid polluting the global namespace.

When I define my import as pin "chartkick", to: "chartkick", it gives me the following error:

Failed to autoload controller: xyz SyntaxError: The requested module 'chartkick' does not provide an export named 'default

However, if I define my import as pin "chartkick", to: "https://ga.jspm.io/npm:chartkick@5.0.1/dist/chartkick.esm.js", it works properly. I believe this is due to JSPM doing some steps to produce a file that is compatible with ES modules (specifically, it defines an export default ..., based on the wrapper already defined here: https://github.com/ankane/chartkick/blob/1da54f89a0b00d2b2870bf63a155025a427acf05/vendor/assets/javascripts/chartkick.js#L8-L12

I think ideally, that precompiled version would be made available through the gem, so we can use it that way.

ankane commented 1 year ago

Hi @dkniffin, see #611.