Error importing Chartkick object
leo-quimbee opened this issue · comments
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.
- add chartkick to importmap
pin "chartkick", to: "chartkick.js"
pin "Chart.bundle", to: "Chart.bundle.js"
- 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"
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.
@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.