42

I installed Rails on my Surface Pro 3 and run into this error after trying to view a page. I have tried several suggestions such as installing rubyracer with libv8 but it didn't help.

TypeError: Object doesn't support this property or method (in c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee)

Here is my gemfile:

source 'http://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer',  platforms: :ruby
# 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
gem 'libv8', '~> 3.16.14.7'

# 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

# Use debugger
# gem 'debugger', group: [:development, :test]

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
gem 'font-awesome-rails'
gem 'simple_form'
gem 'devise'
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Matt P
  • 593
  • 2
  • 7
  • 19
  • I've had the best luck with http://rubyinstaller.org/ on windows, never tried on a surface, but it might be worth a shot... – Brad Werth Feb 04 '15 at 07:16
  • possible duplicate of [What do I need to do to get the blog to work in rails 4.2?](http://stackoverflow.com/questions/28240245/what-do-i-need-to-do-to-get-the-blog-to-work-in-rails-4-2) – irowe Sep 08 '15 at 21:37

5 Answers5

106

Coffee script 1.9.0 doesn't play well with Windows. On my Windows 7 machine, using version 1.8.0 solved this problem.

Add to Gemfile

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

then, run

bundle update coffee-script-source

and restart the server (if needed)

shafir
  • 38
  • 3
Jessa
  • 1,549
  • 2
  • 12
  • 26
  • 4
    Forcing `coffee-script-source` to 1.8.0 worked perfectly for me, Rails 4.1.1, `coffee-script` 2.3.0, `coffee-rails` 4.0.1 – lurker Mar 05 '15 at 16:50
  • 1
    Thanks that fixed it for me (without modifing `runtimes.rb`) – rmaVT Mar 10 '15 at 20:03
  • @RichPeck agreed. Sooner or later we'll need to update coffee-script, and/or something that depends on it. I'll try to keep this answer updated when that happens. – Jessa Mar 10 '15 at 20:11
  • 1
    if this fixed the issue for the above question, the answer needs to be selected as the correct answer. This did work for me as well. Thank you. – FilBot3 Oct 28 '15 at 16:30
  • NOTE: If `bundle update ...` doesn't work, because of a _command not found error_ then you need to install the bundler first by calling: `gem install bundler` . . . . . Note 2: For installing call "bundleR" with R at the end of the word. For using call "bundle" without R at the end. – Beauty Aug 14 '16 at 15:14
  • I couldn't find an issue anywhere for this, so I created one: https://github.com/rails/coffee-rails/issues/87 – zrisher Mar 19 '17 at 03:02
15

Had the same issue (doing a 'hello world' application of all things...) but couldn't get the coffeescript 1.8.0 fix to work. Found a solution here: http://mech.xyz/how-to-fix-ruby-on-rails-turbolinks-js-coffee-error-windows/

Steps:

  1. Navigate to \app\views\layouts\application.html.erb
  2. Change line 6 from

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

to

<%= javascript_include_tag '**defaults**', 'data-turbolinks-track' => true %>

Did this and it's been working fine now.

Piotr Olaszewski
  • 6,017
  • 5
  • 38
  • 65
Jaime
  • 159
  • 1
  • 2
  • It worked for me in a 'hello world' application, but not in the real one. Seems like turbolinks doesn't work properly in such way. – Ilya Sep 15 '15 at 08:36
  • In my case, it was in `app\views\shared\backend\_javascripts.html.erb` and `app\views\shared\_javascripts.html.erb`. But it only got me so far; then I started seeing blank pages. – Steve Pitchers Nov 03 '15 at 16:32
  • This would cause the js to throw an error before the coffeescript is loaded... not a real solution – KthProg Apr 29 '17 at 14:38
8

Contrary to popular belief, Rails is NOT cross platform compatible as they claim. If it was it would work on windows, out of the box. Like you I have tried every available option.

This was solved using Ruby 2.1.5p273/Rails 4.2.0

I changed execjs to use UTF-8 with jscript, no effect. This was done by editing C:\RailsInstaller\Ruby2.1.0\lib\ruby\gems\2.1.0\gems\execjs-2.2.2\lib\execjs\runtimes.rb changing the JScript = block to the following.

JScript = ExternalRuntime.new(
  name:        "JScript",
  command:     "cscript //E:jscript //Nologo",
  runner_path: ExecJS.root + "/support/jscript_runner.js",
  encoding:    'UTF-8' # CScript with //U returns UTF-16LE
)

I also tried installing therubyracer which leads to problems with the libv8 dependency not compiling. I added my python 2.7 install to the windows system path, and installed libv8. Then it said libv8 was installed but when I tried to install therubyracer it said libv8 couldn't be found. I uninstalled libv8 and tried again and it said libv8 couldn't be compiled. That was enough for me to determine that therubyracer was not going to work on windows, so I commented it out of my Gemfile, leaving python 2.7 on my windows system path.

I updated coffee-script-source, by adding the following to my Gemfile

gem 'coffee-script-source', '1.9.0'

After adding coffee-script-source to my Gemfile I ran gem update coffee-script-source , this also didn't solve the problem.

I then installed node.js, this worked for 5 minutes until I generated a new controller, and it was broken again.

Note: After installing node.js you need to open a new command prompt to get the updates to your system path that are setup when node.js installs.

Finally what fixed this problem was to open up the app\assets\javascripts\application.js file and remove the last line which says

//= require_tree .

Lastly run the following command to make sure coffee-script is properly installed in Node.js

npm install -g coffee-script
Ralph Ritoch
  • 3,260
  • 27
  • 37
  • This was installed using rubyinstaller.org. I got the rid of the tree line and it still happens. So frustrating! – Matt P Feb 04 '15 at 11:53
  • As suggested in this answer I've also installed node.js and added python (2.7) to my system path. Those steps could be playing a role, but I also just installed ruby using railsinstaller though I ended up with Ruby 2.1.0. – Ralph Ritoch Feb 04 '15 at 11:57
  • 1
    I forgot to mention adding gem 'coffee-script-source', '1.9.0' to my gemfile, but I'm not sure and doing a gem update on coffee-script-source, that could also have an effect on the outcome. I really tried everything I could find. – Ralph Ritoch Feb 04 '15 at 12:01
  • One additional note. After installing node.js, and adding python 2 to your windows path, make sure you start the server from a new command prompt. Updates to windows path don't effect command prompts that are already open. – Ralph Ritoch Feb 04 '15 at 12:16
  • Thank you for all of these suggestions. What is the proper way to add python 2 to the windows path? – Matt P Feb 05 '15 at 16:39
  • @Matt P, from the start menu, right click on This PC, and select properties from the context menu. Then click advanced system properties on the left, finally click the button at the bottom which says Environment Variables, select the PATH variable, and click the edit button. – Ralph Ritoch Feb 05 '15 at 16:42
  • I added C:\python2.7\ to the path. Do i have to add any gems with node or do i have to add that to the path as well? – Matt P Feb 07 '15 at 23:58
  • @Matt, Node is automatically detected. If you use the windows installer of Node.js it will automatically update your path. – Ralph Ritoch Feb 08 '15 at 03:16
  • It says Node is not available on this system. Very strange. – Matt P Feb 10 '15 at 22:21
  • @Matt, take a look at this issue, it could be related to your Node.js problem. http://stackoverflow.com/questions/25093276/node-js-windows-error-enoent-stat-c-users-rt-appdata-roaming-npm – Ralph Ritoch Feb 10 '15 at 23:12
  • 1
    @Matt, I was able to restore the "//= require_tree . " to application.js by running npm install -g coffee-script , let me know if this resolves your problem. – Ralph Ritoch Feb 14 '15 at 03:27
  • 1
    Truth: "Contrary to popular belief, Rails is NOT cross platform compatible as they claim. If it was it would work on windows, out of the box." – ed209 Mar 06 '15 at 19:04
7

This is caused by an incompatibility between 64bit Windows and the CoffeeScript gem.

This is indeed a CoffeeScript issue. It only appears to affect 64 bit Windows machines. 32bit Windows is fine.

CoffeeScript occurs in two places by default in Rails:

  • The default scaffold generator makes a coffee script file.
  • Turbolinks is CoffeeScript.

The simplest way to fix this is to simply remove the CoffeeScript. You probably don't need it anyway.

  1. Delete the generated coffeeScript file in app/assets/javascripts.
  2. Remove the turbolinks gem from the gemfile, then bundle install.
  3. Edit assets/stylesheets/application.js to delete the turbolinks include.
superluminary
  • 47,086
  • 25
  • 151
  • 148
4

I found your error look like this ExecJS::RuntimeError on Windows trying to follow rubytutorial

I fix on my system by un-comment the line // = require_tree in 'assets\javascripts\application.js'

= require_tree
Community
  • 1
  • 1
suhao399
  • 628
  • 7
  • 11
  • This would cause the js to throw an error before the coffeescript is loaded... not a real solution – KthProg Apr 29 '17 at 14:38