0

I have a JQuery error after deploying my app on Heroku

I use Rails 5.2. So this error prevents all the following js code to load.

Gemfile :

gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'bootstrap', '~> 4.0.0'

Application.js

//= require rails-ujs
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jquery.mCustomScrollbar.concat.min
//= require bootstrap
// require turbolinks
//= require_tree .
//

I precompiled my assets before deploying to heroku with :

RAILS_ENV=production bundle exec rake assets:precompile

The ERROR :

Uncaught TypeError: t.indexOf is not a function

I inspected the error, and it comes from this function :

/*!
 * Sizzle CSS Selector Engine v2.3.3
 * https://sizzlejs.com/
 *
 * Copyright jQuery Foundation and other contributors
 * Released under the MIT license
 * http://jquery.org/license
 *
 * Date: 2016-08-08
 */

Go to deployed page on heroku and open up the console to see the error.

Any ideas ?

  • Where do you get this error? – Loqman Aug 23 '18 at 10:03
  • @Loqman in the console. You can check it here : https://calm-depths-37631.herokuapp.com/login – Larry Bird Aug 23 '18 at 10:06
  • As I can see. You are using Jquery "3.2.1" version. Can you try with lower version "2.1.0" or below? You can check something relevant on this link https://stackoverflow.com/questions/38871753/uncaught-typeerror-a-indexof-is-not-a-function-error-when-opening-new-foundat . Let me know if does not work. – Anshul Aug 23 '18 at 10:17
  • This error might be caused by jQuery event aliases like `.load`, `.unload` or `.error` deprecated since jQuery 1.8 and removed in 3.0. As @Anshul suggested try using older version of jQuery and see if it works. – Loqman Aug 23 '18 at 10:26
  • 1
    @Loqman It seems to work with JQuery2 ! `//= require jquery2` in my application.js – Larry Bird Aug 23 '18 at 12:25
  • @LarryBird Since the comment worked for you, I have posted it as an answer. Please go ahead and accept it as the solution. – Loqman Aug 23 '18 at 13:02

1 Answers1

0

This error might be caused by jQuery event aliases like .load, .unload or .error deprecated since jQuery 1.8 and removed in 3.0.

Using lower versions like 2.1 will solve your problem.

Loqman
  • 1,487
  • 1
  • 12
  • 24