[Chartjs]-Using chart.js with importmaps in rail 7

4๐Ÿ‘

I was able to solve this by fetching the library from the CDN rather than downloading it. To do this, I first unpinned the downloaded version:

bin/importmap unpin chart.js --download

and then I repinned it without downloading:

bin/importmap pin chart.js

And now it works!

0๐Ÿ‘

As of August 2023, the setup for Chartkick (which uses chart.js) with Importmap is described in the Chartkick documentation, which worked for me.

Importmap
In config/importmap.rb, add:

pin "chartkick", to: "chartkick.js"
pin "Chart.bundle", to: "Chart.bundle.js"

And in app/javascript/application.js, add:

import "chartkick"
import "Chart.bundle"

Leave a comment