I am trying to use Select2 on a new Rails 7 app and am struggling as follows:
I have pinned it into my import maps and imported it like so:
pin "application", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin_all_from "app/javascript/controllers", under: "controllers"
pin "trix"
pin "@rails/actiontext", to: "actiontext.js"
pin "select2", to: "https://ga.jspm.io/npm:[email protected]/dist/js/select2.js"
pin "jquery", to: "https://ga.jspm.io/npm:[email protected]/dist/jquery.js"
(the two last lines were added when I run bin/importmap pin select2)
import "jquery";
import "select2";
import "@hotwired/turbo-rails";
import "controllers";
import "trix";
import "@rails/actiontext";
(have moved both jquery and select2 to the end as well as to the beginning - didn't change a thing).
When I am in a form, I can access an element with $ like so:
$('#book_genre_ids');
...(returns the element)
But when I manually try - in the console - to run select2() on an element, here's what happens:
$('#book_genre_ids').select2();
VM574:1 Uncaught TypeError: $(...).select2 is not a function
at <anonymous>:1:22
I did check the network sources (chrome console), and I could find npm:[email protected]/dist and npm:[email protected]/dist from gap.jspm.io. I found some resources that pointed at multiple jquery libraries being loaded, but I didn't find more than the above in the network sources in the console...