Search code examples
javascriptruby-on-railsstimulusjshotwire-rails

Failed to resolve module specifier "stimulus-autocomplete"


Ruby 3.0.3 Rails 7.0.0.alpha2

After following the instructions to install and usage, I launch the server and I received this error: Uncaught TypeError: Failed to resolve module specifier "stimulus-autocomplete". Relative references must start with either "/", "./", or "../".

# app/javascript/controllers/application.js
import { Application } from "@hotwired/stimulus"
import { Autocomplete } from "stimulus-autocomplete"
# and tried import { Autocomplete } from 'stimulus-autocomplete/src/autocomplete'

const application = Application.start()
application.register('autocomplete', Autocomplete)

// Configure Stimulus development experience
application.debug = false
window.Stimulus   = application

export { application }

Solution

  • If you use import maps, did you add "stimulus-autocomplete" in your config/importmap.rb so the lib can be imported?

    pin "stimulus-autocomplete", to: "https://cdn.jsdelivr.net/npm/[email protected]/src/autocomplete.min.js"