前提
Rails7のimportmap-railsを利用してChoices.jsを実装したいのですが、エラーが出てしまいました。
https://github.com/Choices-js/Choices
発生している問題・エラーメッセージ
Failed to register controller: select (controllers/select_controller) SyntaxError: The requested module 'choices.js' does not provide an export named 'default'
該当のソースコード
JavaScript
1//app > javascript > controllers > select_controller.js 2 3import {Controller} from "@hotwired/stimulus" 4import Choices from "choices.js" 5 6console.log('select_controller'); 7export default class extends Controller { 8 connect() { 9 this.choices = Choices.create(this.element, {}) 10 } 11}
Ruby
1# importmap.rbに下記を追加 2pin "choices.js", to: "https://cdn.jsdelivr.net/npm/choices.js@10.1.0/public/assets/scripts/choices.js"
Ruby
1# index.html.erb 2<select data-controller="select" name="spice"> 3 <option value="">スパイスを選択</option> 4 <option value="garammasala">ガラムマサラ</option> 5 <option value="coriander">コリアンダー</option> 6 <option value="cumin">クミン</option> 7</select>
試したこと
index.html.erbにchoices.jsリンクなどを直接書き込んで動作確認を行った
importmapsの使い方について学び、Sortable.jsを実装した:https://youtu.be/veWpot6zfUQz
補足情報(FW/ツールのバージョンなど)
Rails 7.0.2.3
ruby 3.1.1

回答1件
あなたの回答
tips
プレビュー