ankane / chartkick

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

Error importing Chartkick object #611

Closed leo-quimbee closed 1 year ago

leo-quimbee commented 1 year ago

Describe the bug I am trying to import the Chartkick object

import Chartkick from "chartkick"

But I get this error

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

To reproduce Steps to reproduce.

  1. add chartkick to importmap

    pin "chartkick", to: "chartkick.js"
    pin "Chart.bundle", to: "Chart.bundle.js"
  2. try to import Chartkick object

    import Chartkick from "chartkick"

    Workaround The work around we found is to point to jspm

    pin "chartkick", to: "https://ga.jspm.io/npm:chartkick@5.0.1/dist/chartkick.esm.js"
ankane commented 1 year ago

Hi @leo-quimbee, to import the included JavaScript file, you'll need to use:

import "chartkick"

I may include the ES module in the gem at some point, but don't see a strong reason for including it now.

dkniffin commented 1 year ago

@ankane thanks for closing my duplicate issue. Leo is a coworker of mine, and I didn't realize we both created the same issue 😅

So am I understanding correctly that we must use a global reference to Chartkick? I'd really prefer not to pollute the global namespace, if at all possible. That should be possible, as long as we have the ES module included in the gem. Or reference the library on JSPM, which we're doing currently, but isn't actually documented in the readme, and we also have to reference Chart.bundle.js via the gem regardless, because it doesn't seem to be available on JSPM.