ExecJS::RuntimeError in Listings#index error

I’m receiving this ExecJS error message when I open my localhost, I don’t know why, some help would be amazing.

I got this on my localhost

Showing /…/conektec/app/views/layouts/application.html.erb where line #6 raised:

  • Exception while simulating the effect of invoking 'upvote'. TypeError: undefined is not a function
  • Bootstrap DatePicker to allow editing through typing
  • Concatenating an array with itself
  • Running JQuery with CoffeeScript
  • Monitoring sub-task for grunt-contrib-watch
  • How to create a small Javascript extension language?
  • SyntaxError: [stdin]:6:16: unexpected newline
    (in /…/conektec/app/assets/javascripts/orders.js.coffee)

      ActionView::Template::Error (SyntaxError: [stdin]:2:73: unmatched )
      (in /Users/hbendev/startups/conektec/conektec/app/assets/javascripts/orders.js.coffee)):
        3: <head>
        4:   <title>Conektec</title>
        5:   <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
        6:   <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
        7:   <%= javascript_include_tag "https://js.stripe.com/v2/" %> 
        8:   <%= csrf_meta_tags %>
        9:   <%= tag :meta, :name => "stripe-key", :content => ENV["STRIPE_PUBLIC_KEY"] %>
    

    Here is my orders.js.coffee file

    jQuery ->
      Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
      payment.setupForm()
    
    payment =
      setupForm: ->
      $('#new_order').submit ->
        $('input[type=submit]').attr('disabled', true)
        Stripe.card.createToken($('#new_order'), payment.handleStripeResponse)
        false
    
    handleStripeResponse: (status, response) ->
      if status == 200
        alert(response.id)
      else
        alert(response.error.message)
    

    Here’s my application.html.erb file

    <!DOCTYPE html>
    <html>
    <head>
      <title>Conektec</title>
      <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
      <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
      <%= javascript_include_tag "https://js.stripe.com/v2/" %> 
      <%= csrf_meta_tags %>
      <%= tag :meta, :name => "stripe-key", :content => ENV["STRIPE_PUBLIC_KEY"] %>
    </head>
    
    <body>
    
    <%= render 'layouts/header' %>
    
    <div class="container">
    
        <% flash.each do |name, msg| %>
            <% if msg.is_a?(String) %>
                <div class="alert alert-<%= name.to_s == 'notice' ? "success" : "danger" %> alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                    <%= content_tag :div, msg, :id => "flash_#{name}" %>
                </div>
            <% end %>
        <% end %>
    
        <%= yield %>
    
        <%= render 'layouts/footer' %>
    </div>
    
    
    </body>
    </html>
    

    I already tried deleting my turbolinks, adding the rubyracer gem, I have nodejs installed, I don’t know where’s the error.

    I’m using:
    OS X Mavericks
    Ruby 2.0.0
    Rails 4.1.1

    What’s wrong? Thanks.

  • Reactjs append an element instead of replacing
  • Do something once jQuery plugin has loaded
  • Ramaze + CoffeeScript : Is it possible to generate Javascript automatically with Ramaze?
  • Exclude route from express middleware
  • Monitoring sub-task for grunt-contrib-watch
  • Why doesn't this CoffeeScript/JavaScript set the properties of created object?
  • One Solution collect form web for “ExecJS::RuntimeError in Listings#index error”

    Your issue is in your CoffeeScript syntax (line 6, column 16, as it states in the error):

    # The lack of indentation after the setupForm line is incorrect
    payment =
      setupForm: ->
      $('#new_order').submit ->
        $('input[type=submit]').attr('disabled', true)
        Stripe.card.createToken($('#new_order'), payment.handleStripeResponse)
        false
    
    # Make it this
    payment = 
      setupForm: ->
        $('#new_order').submit ->
          $('input[type=submit]').attr('disabled', true)
          Stripe.card.createToken($('#new_order'), payment.handleStripeResponse)
          false
    

    Edit: it’s worth noting that whenever there is an ExecJS error, it’s usually a pretty good sign that there’s an issue with your CoffeeScript syntax (thus causing a compilation error). It’s not an actual JavaScript error in this case.’

    To fix the OTHER issue you’re having, since I can’t comment, you need to indent your handleStripeResponse function so that it is nested underneath your payment object:

    jQuery ->
      Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
      payment.setupForm()
    
    payment =
      setupForm: ->
        $('#new_order').submit ->
          $('input[type=submit]').attr('disabled', true)
          Stripe.card.createToken($('#new_order'), payment.handleStripeResponse)
          false
    
      handleStripeResponse: (status, response) ->
        if status == 200
          alert(response.id)
        else
          alert(response.error.message)
    

    I’m not sure how you have these errors, considered they are copied directly from the Railscasts episode; try to be very careful about your indentation with CoffeeScript.