title: Error When Running easyAutocomplete in Rails 6 - easyAutocomplete is not a function
body: <p>I followed this tutorial but I'm running into an issue: <a href="https://gorails.com/episodes/global-autocomplete-search" rel="nofollow noreferrer">https://gorails.com/episodes/global-autocomplete-search</a></p>
  <p>I am getting an error in the js console when refresh the page: <code>search.js:31 Uncaught TypeError: $input.easyAutocomplete is not a function</code></p>
  <p>However, when I put create an options variable directly in the console and run:
  <code>$input = $(&quot;[data-behavior='autocomplete']&quot;)</code>
  and then
  <code>$input.easyAutocomplete(options)</code>
  it works fine. Any idea why I am able to run easyAutocomplete directly in the console but not in the normal course of my app? Here is my application.js file:</p>
  <pre><code>// Rails functionality
  window.Rails = require(&quot;@rails/ujs&quot;)
  require(&quot;turbolinks&quot;).start()
  require(&quot;@rails/activestorage&quot;).start()
  require(&quot;channels&quot;)
  require(&quot;trix&quot;)
  require(&quot;@rails/actiontext&quot;)
  
  require(&quot;jquery&quot;)
  require(&quot;easy-autocomplete&quot;)
  
  require(&quot;custom/show&quot;)
  require(&quot;custom/search&quot;)
  
  // Tailwind CSS
  import &quot;stylesheets/application&quot;
  
  // Stimulus controllers
  import &quot;controllers&quot;
  
  // Jumpstart Pro &amp; other Functionality
  import &quot;src/actiontext&quot;
  import &quot;src/confirm&quot;
  import &quot;src/direct_uploads&quot;
  import &quot;src/forms&quot;
  import &quot;src/timezone&quot;
  import &quot;src/tooltips&quot;
  
  import LocalTime from &quot;local-time&quot;
  LocalTime.start()
  
  // ADD YOUR JAVACSRIPT HERE
  
  // Start Rails UJS
  Rails.start()
  </code></pre>
  <p>Any ideas on this? Thanks!</p>
  <p><strong>Edit 1 - added search.js:</strong></p>
  <p><em>search.js</em></p>
  <pre><code>$(document).on('turbolinks:load', function() {
      if ($('#search-input').length) {
          console.log('in search.js')
          $input = $(&quot;[data-behavior='autocomplete']&quot;)
  
          var options = {
          getValue: &quot;name&quot;,
          url: function(phrase) {
            return &quot;/search.json?q=&quot; + phrase;
          },
              categories: [
                  {
                      listLocation: &quot;entities&quot;,
                      header: &quot;&lt;strong&gt;Entities&lt;/strong&gt;&quot;
                  },
                  {
                      listLocation: &quot;tags&quot;,
                      header: &quot;&lt;strong&gt;Tags&lt;/strong&gt;&quot;
                  }
              ],
              list: {
                  onChooseEvent: function() {
                      var url = $input.getSelectedItemData().url
              $input.val(&quot;&quot;)
              Turbolinks.visit(url)
                  }
              }
          }
  
          $input.easyAutocomplete(options)
      }
  })
  </code></pre>