Rails ExecJS::ProgramError in Pages#home?

70,287

Solution 1

In your /app/views/layouts/application.html.erb lines 5 and 6, change the first parameter from application to default.

I met the same problem, too for my situation, I don't know why, but it only happens on Windows. The parameter application works on the web server.

Solution 2

If you are running in WIndows, the coffee-script-source 1.9.0 does not work on windows.

Change it to a previous version adding this line to your Gemfile:

gem 'coffee-script-source', '1.8.0'

And then reinstall the bundle adjusting the dependencies for the new Gem version with:

bundle update coffee-script-source

Solution 3

I've been having this issue for a while and having gone through all the answers in this thread and found them all to be unsuccessful, I've decided to add my solution in hopes that it helps future Rails users.

I've done everything in this thread - changing application to default allows it to go through without an error, but then once you actually try to use any JavaScript, an error is displayed regarding not being able to find default.js. I've installed NodeJS and put it in my Ruby/bin folder. That did nothing, so I removed it.

You can indeed temporarily get around this problem with the "switching out application with default" solution, but it's extremely short term. This solution may work for you if you have no intention of styling or adding JavaScript to your app through the Rails asset pipeline. I have not tested this myself, but I imagine including JavaScript and stylesheets in the application.html header file may work. But then you lose the magic of Rails.

I have had this issue on Windows 8, Windows 10, and Ubuntu platforms.

The only thing that solves it, for me, and still renders the JavaScript and stylesheets is to first change application to application.css for the stylesheets (even if you're using Sass/SCSS, because it still compiles down into css) and application.js for the JavaScript link. Once that is done, go into your /assets/javascripts/application.js file and delete the // in front of //= require turbolinks.

And now your application should work just fine.

This is probably a deeper issue with turbolinks, but this is a quick workaround that hasn't let me down yet.

Solution 4

in windows coffee-script source >= 1.9.0 not work properly. just add in Gemfile

 gem 'coffee-script-source', '1.8.0'

and run

bundle update coffee-script-source

Solution 5

Just install NodeJS on your local machine (make sure the correspodning entry is added to the PATH) and add

gem 'execjs'

into the Gemfile.

Share:
70,287
AB10
Author by

AB10

Updated on May 14, 2020

Comments

  • AB10
    AB10 about 4 years

    Starting a new app, when I create a controller page home and try to go to local host:3000/pages/home, I get the following error:

    Showing c:/Users/Doesha/desktop/pinplug/app/views/layouts/application.html.erb where line #6 raised:
    
    TypeError: Object doesn't support this property or method
      (in c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee)
    

    application.html.erb file:

    <!DOCTYPE html>
    <html>
    <head>
      <title>Pinplug</title>
      <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
      <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
      <%= csrf_meta_tags %>
    </head>
    <body>
    
    <%= yield %>
    
    </body>
    </html>
    

    application_controller.rb file:

    class ApplicationController < ActionController::Base
      # Prevent CSRF attacks by raising an exception.
      # For APIs, you may want to use :null_session instead.
      protect_from_forgery with: :exception
    end
    

    pages_controller.rb file:

    class PagesController < ApplicationController
      def home
      end
    end
    

    routes.rb file:

    Rails.application.routes.draw do
      get 'pages/home'
    
      # The priority is based upon order of creation: first created -> highest priority.
      # See how all your routes lay out with "rake routes".
    
      # You can have the root of your site routed with "root"
      # root 'welcome#index'
    
      # Example of regular route:
      #   get 'products/:id' => 'catalog#view'
    
      # Example of named route that can be invoked with purchase_url(id: product.id)
      #   get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
    
      # Example resource route (maps HTTP verbs to controller actions automatically):
      #   resources :products
    
      # Example resource route with options:
      #   resources :products do
      #     member do
      #       get 'short'
      #       post 'toggle'
      #     end
      #
      #     collection do
      #       get 'sold'
      #     end
      #   end
    
      # Example resource route with sub-resources:
      #   resources :products do
      #     resources :comments, :sales
      #     resource :seller
      #   end
    
      # Example resource route with more complex sub-resources:
      #   resources :products do
      #     resources :comments
      #     resources :sales do
      #       get 'recent', on: :collection
      #     end
      #   end
    
      # Example resource route with concerns:
      #   concern :toggleable do
      #     post 'toggle'
      #   end
      #   resources :posts, concerns: :toggleable
      #   resources :photos, concerns: :toggleable
    
      # Example resource route within a namespace:
      #   namespace :admin do
      #     # Directs /admin/products/* to Admin::ProductsController
      #     # (app/controllers/admin/products_controller.rb)
      #     resources :products
      #   end
    end
    

    gemfile:

    source 'https://rubygems.org'
    
    
    # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
    gem 'rails', '4.2.0'
    # Use sqlite3 as the database for Active Record
    gem 'sqlite3'
    # Use SCSS for stylesheets
    gem 'sass-rails', '~> 5.0'
    # Use Uglifier as compressor for JavaScript assets
    gem 'uglifier', '>= 1.3.0'
    # Use CoffeeScript for .coffee assets and views
    gem 'coffee-rails', '~> 4.1.0'
    # See https://github.com/sstephenson/execjs#readme for more supported runtimes
    # gem 'therubyracer', platforms: :ruby
    
    gem 'execjs', '~> 2.2.2'
    
    # Use jquery as the JavaScript library
    gem 'jquery-rails'
    # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
    gem 'turbolinks'
    # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
    gem 'jbuilder', '~> 2.0'
    # bundle exec rake doc:rails generates the API under doc/api.
    gem 'sdoc', '~> 0.4.0', group: :doc
    
    # Use ActiveModel has_secure_password
    # gem 'bcrypt', '~> 3.1.7'
    
    # Use Unicorn as the app server
    # gem 'unicorn'
    
    # Use Capistrano for deployment
    # gem 'capistrano-rails', group: :development
    
    group :development, :test do
      # Call 'byebug' anywhere in the code to stop execution and get a debugger console
      gem 'byebug'
    
      # Access an IRB console on exception pages or by using <%= console %> in views
      gem 'web-console', '~> 2.0'
    end
    
    # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
    gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
    

    gemfile.lock file:

    GEM
      remote: https://rubygems.org/
      specs:
        actionmailer (4.2.0)
          actionpack (= 4.2.0)
          actionview (= 4.2.0)
          activejob (= 4.2.0)
          mail (~> 2.5, >= 2.5.4)
          rails-dom-testing (~> 1.0, >= 1.0.5)
        actionpack (4.2.0)
          actionview (= 4.2.0)
          activesupport (= 4.2.0)
          rack (~> 1.6.0)
          rack-test (~> 0.6.2)
          rails-dom-testing (~> 1.0, >= 1.0.5)
          rails-html-sanitizer (~> 1.0, >= 1.0.1)
        actionview (4.2.0)
          activesupport (= 4.2.0)
          builder (~> 3.1)
          erubis (~> 2.7.0)
          rails-dom-testing (~> 1.0, >= 1.0.5)
          rails-html-sanitizer (~> 1.0, >= 1.0.1)
        activejob (4.2.0)
          activesupport (= 4.2.0)
          globalid (>= 0.3.0)
        activemodel (4.2.0)
          activesupport (= 4.2.0)
          builder (~> 3.1)
        activerecord (4.2.0)
          activemodel (= 4.2.0)
          activesupport (= 4.2.0)
          arel (~> 6.0)
        activesupport (4.2.0)
          i18n (~> 0.7)
          json (~> 1.7, >= 1.7.7)
          minitest (~> 5.1)
          thread_safe (~> 0.3, >= 0.3.4)
          tzinfo (~> 1.1)
        arel (6.0.0)
        binding_of_caller (0.7.2)
          debug_inspector (>= 0.0.1)
        builder (3.2.2)
        byebug (3.5.1)
          columnize (~> 0.8)
          debugger-linecache (~> 1.2)
          slop (~> 3.6)
        coffee-rails (4.1.0)
          coffee-script (>= 2.2.0)
          railties (>= 4.0.0, < 5.0)
        coffee-script (2.3.0)
          coffee-script-source
          execjs
        coffee-script-source (1.9.0)
        columnize (0.9.0)
        debug_inspector (0.0.2)
        debugger-linecache (1.2.0)
        erubis (2.7.0)
        execjs (2.2.2)
        globalid (0.3.2)
          activesupport (>= 4.1.0)
        hike (1.2.3)
        i18n (0.7.0)
        jbuilder (2.2.6)
          activesupport (>= 3.0.0, < 5)
          multi_json (~> 1.2)
        jquery-rails (4.0.3)
          rails-dom-testing (~> 1.0)
          railties (>= 4.2.0)
          thor (>= 0.14, < 2.0)
        json (1.8.2)
        loofah (2.0.1)
          nokogiri (>= 1.5.9)
        mail (2.6.3)
          mime-types (>= 1.16, < 3)
        mime-types (2.4.3)
        mini_portile (0.6.2)
        minitest (5.5.1)
        multi_json (1.10.1)
        nokogiri (1.6.6.2-x86-mingw32)
          mini_portile (~> 0.6.0)
        rack (1.6.0)
        rack-test (0.6.3)
          rack (>= 1.0)
        rails (4.2.0)
          actionmailer (= 4.2.0)
          actionpack (= 4.2.0)
          actionview (= 4.2.0)
          activejob (= 4.2.0)
          activemodel (= 4.2.0)
          activerecord (= 4.2.0)
          activesupport (= 4.2.0)
          bundler (>= 1.3.0, < 2.0)
          railties (= 4.2.0)
          sprockets-rails
        rails-deprecated_sanitizer (1.0.3)
          activesupport (>= 4.2.0.alpha)
        rails-dom-testing (1.0.5)
          activesupport (>= 4.2.0.beta, < 5.0)
          nokogiri (~> 1.6.0)
          rails-deprecated_sanitizer (>= 1.0.1)
        rails-html-sanitizer (1.0.1)
          loofah (~> 2.0)
        railties (4.2.0)
          actionpack (= 4.2.0)
          activesupport (= 4.2.0)
          rake (>= 0.8.7)
          thor (>= 0.18.1, < 2.0)
        rake (10.4.2)
        rdoc (4.2.0)
          json (~> 1.4)
        sass (3.4.11)
        sass-rails (5.0.1)
          railties (>= 4.0.0, < 5.0)
          sass (~> 3.1)
          sprockets (>= 2.8, < 4.0)
          sprockets-rails (>= 2.0, < 4.0)
          tilt (~> 1.1)
        sdoc (0.4.1)
          json (~> 1.7, >= 1.7.7)
          rdoc (~> 4.0)
        slop (3.6.0)
        sprockets (2.12.3)
          hike (~> 1.2)
          multi_json (~> 1.0)
          rack (~> 1.0)
          tilt (~> 1.1, != 1.3.0)
        sprockets-rails (2.2.4)
          actionpack (>= 3.0)
          activesupport (>= 3.0)
          sprockets (>= 2.8, < 4.0)
        sqlite3 (1.3.10-x86-mingw32)
        thor (0.19.1)
        thread_safe (0.3.4)
        tilt (1.4.1)
        turbolinks (2.5.3)
          coffee-rails
        tzinfo (1.2.2)
          thread_safe (~> 0.1)
        tzinfo-data (1.2015.1)
          tzinfo (>= 1.0.0)
        uglifier (2.7.0)
          execjs (>= 0.3.0)
          json (>= 1.8.0)
        web-console (2.0.0)
          activemodel (~> 4.0)
          binding_of_caller (>= 0.7.2)
          railties (~> 4.0)
          sprockets-rails (>= 2.0, < 4.0)
    
    PLATFORMS
      x86-mingw32
    
    DEPENDENCIES
      byebug
      coffee-rails (~> 4.1.0)
      execjs (~> 2.2.2)
      jbuilder (~> 2.0)
      jquery-rails
      rails (= 4.2.0)
      sass-rails (~> 5.0)
      sdoc (~> 0.4.0)
      sqlite3
      turbolinks
      tzinfo-data
      uglifier (>= 1.3.0)
      web-console (~> 2.0)
    

    application.rb file:

    require File.expand_path('../boot', __FILE__)
    
    require 'rails/all'
    
    # Require the gems listed in Gemfile, including any gems
    # you've limited to :test, :development, or :production.
    Bundler.require(*Rails.groups)
    
    module Pinplug
      class Application < Rails::Application
        # Settings in config/environments/* take precedence over those specified here.
        # Application configuration should go into files in config/initializers
        # -- all .rb files in that directory are automatically loaded.
    
        # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
        # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
        # config.time_zone = 'Central Time (US & Canada)'
    
        # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
        # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
        # config.i18n.default_locale = :de
    
        # Do not swallow errors in after_commit/after_rollback callbacks.
        config.active_record.raise_in_transactional_callbacks = true
      end
    end
    

    I also downgraded the turbolinks gem from 2.3.0 to 2.2.2, thinking that the newer version of the turbolinks gem was causing my app to have errors; obviously that didn't work for me.

    Any suggestions on what could be going wrong with my app?

  • AB10
    AB10 over 9 years
    Thanks @felipe.zkn, I've been trying to figure this thing out for a while. I'll have to remember that rule!!
  • felipe.zkn
    felipe.zkn over 9 years
    @AB10 I just editted the answer. Please, notify the answerer.
  • AB10
    AB10 over 9 years
    Thanks @FlyC, I appreciate that!
  • MSC
    MSC over 9 years
    Huh! Same thing for me after I upgraded from Rails 4.1.1 to 4.2 on Windows. Thanks for the answer. Nothing in the upgrade docs about this at all! #@^$@# So how did you figure this out?
  • Michael Petch
    Michael Petch over 9 years
    coffee-script source >= 1.9.0 don't work properly under Windows. You can do this: gem 'coffee-script-source', '1.8.0' to force 1.8.0 and then issue bundle update coffee-script-source
  • armstrhb
    armstrhb about 9 years
    Thanks @MichaelPetch, your comment is the thing that worked for me!
  • Michael Petch
    Michael Petch about 9 years
    @armstrhb I believe that my comment is probably the proper answer to this question (and the root cause of the problems). I should consider adding it as an actual answer to this question
  • jameshwart lopez
    jameshwart lopez about 9 years
    it works on mine also but if we try to look at the console default.js is 404 already
  • Jeff
    Jeff almost 9 years
    Also, restart the server (somewhat obvious, but It got me).
  • e-fisher
    e-fisher over 8 years
    Changing 'application' to 'default' won't solve the problem, if you check dev tools you'll see assets are not included due to 404. Downgrading coffe-script-source is the correct answer.
  • user4571629
    user4571629 over 8 years
    I agree with @excel66 - That's right, I can't believe people actually doing that or making this answer as a positive one, that's really not the solution because let's say you have CSS file on this folder \assets\stylesheets it won't load it,
  • TylerH
    TylerH over 8 years
    What makes you think this is a better solution than the year-old accepted answer?
  • Jonathan Harvey
    Jonathan Harvey about 8 years
    I think this is a better solution because changing "application" to "default" in the /layouts/application.html.erb can cause CSS and JS files throw a 404. Installing Node.js doesn't require you to make changes in your code that either produces undesired results (scripts and stylesheets not loading), or causes you to have to make widespread changes in code when moving to production.
  • illiquent
    illiquent about 8 years
    this solution worked for me on windows 10, and allowed ruby to see the other style sheets I had in the "pipeline". changing 'application' to 'default' - indeed breaks the stylesheets. perhaps it is just a coffescript error at the cause - but this solution worked great.
  • illiquent
    illiquent about 8 years
    this solution works on windows 10. make sure you restart the server like Jeff says.
  • MSC
    MSC about 8 years
    I am on Windows 10 and I agree with e-fisher (above). Changing 'application' to 'default' merely prevented the app from finding the appropriate JS and CSS files. To get the app to find and execute application.js without error, I needed to downgrade coffee-script-source.
  • Arthur
    Arthur almost 8 years
    Over a year later now Rails 5.0.0.1 and the same bug. Looks like nobody cares about Windows, it is like a tax, if you chose Windows and develop in Ruby on Rails then you waste time. But seriously, this nuance has to be fixed please.
  • nour
    nour over 7 years
    Thank you so much!
  • Arthur
    Arthur over 7 years
    By the way as a result of this seemingly benign change other parts break as for example integration with Bootstrap. Fixable, but requires to hop through the loops.
  • Sassy Llama
    Sassy Llama over 7 years
    wow; I'd give you +150 if I could. thank you so much. this worked on win 7 x64
  • Angelo
    Angelo over 7 years
    THIS is the SOLUTION! Thanks!
  • Angelo
    Angelo over 7 years
    This isn't the solution! The solution is: add in Gemfile gem 'coffee-script-source', '1.8.0' and run bundle update coffee-script-source
  • dbeachy1
    dbeachy1 over 7 years
    Angelo's solution worked for me (I'm using Rails 4 on Windows 10 x64). Nothing else worked for me, but downgrading to coffee-script-source 1.8.0 did the trick. Thanks, Angelo! P.S. I really wish the Rails devs would fix this, Windows gets no love. :(
  • Angel
    Angel about 7 years
    Hi sir, I did what you've said.. it's still not working.. Why?
  • Forrest
    Forrest about 6 years
    I had not realized that NodeJS wasn't installed on my machine. I found this video which basically solves it the same way youtube.com/watch?reload=9&v=l04kFL3pnEk and speaks to installing NodeJS on a windows machine.
  • Jeffrey M Castro
    Jeffrey M Castro about 6 years
    this is the solution i used in my Windows Server 2016
  • Rafaf Tahsin
    Rafaf Tahsin almost 6 years
    Works on Windows 10 too. Tested
  • Syamsoul Azrien
    Syamsoul Azrien over 5 years
    this is working for me....for my case, node is already installed, but it doesn't include in ENVIRONMENT PATH VARIABLE....so i just add it to path variable....that's it
  • Chait
    Chait almost 5 years
    I had the same issue, and changing "application" to "default" threw the exception that "application.css" couldn't be found. but, this solution did work for me. thanks!