What is Javascript-Runtime for?

Hello Everyone,

Can anyone please describe the relationship of javascript-runtime to Ruby on Rails? In Mac OSX, I do not get this error, but in Linux for every new project generated by “rails new”, I get:

play$ rails s //.rvm/gems/ruby-2.0.0-p0/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect’: Could not find a JavaScript runtime. See GitHub - sstephenson/execjs: Run JavaScript code from Ruby for a list of available runtimes.

I know the solution; either install therubyracer or nodejs gems. But I am not sure I understand fully why it works. If I install this in a production environment server, I do not need either one of these. And my browser definitely interprets javascript built in. So how does this fit in to everything? Is my premise incorrect? Thank you.

Peter

There are asset pipeline dependencies here: for example uglifyjs (for minifying javascript) and coffeescript are both written in javascript. Both of these two things happen serverside (almost: you can compile the assets somewhere other than your deployment machines, and copy the finished product either to the deployment machines or to the CDN of your choice)

Fred

Thanks for replying, Frederick. So help me understand this: javascript-runtime is actually the javascript interpreter. Right? But what is odd is when I install node-js this solves my problem. And I thought node-js was written in javascript. Therefore, it itself requires an interpreter. Did I get this wrong? So how does installing node-js, a javascript script, solve the problem of not having a javascript interpreter to begin with?

Thanks again.

just a small add to the topic, node.js is not written in javascript… it allows you to write your stuff, using javascript.

http://en.wikipedia.org/wiki/Nodejs

actually its very compatible with coffee script which is, in my opinion, way more fun than javascript ( :

http://coffeescript.org/

Thanks for replying, Frederick. So help me understand this: javascript-runtime is actually the javascript interpreter. Right? But what is odd is when I install node-js this solves my problem. And I thought node-js was written in javascript. Therefore, it itself requires an interpreter. Did I get this wrong? So how does installing node-js, a javascript script, solve the problem of not having a javascript interpreter to begin with?

Node.js is based on the Google's javascript engine, I believe, which is not written in javascript. With it comes a javascript library to extend the features (which is run by the javascript engine of course).

Colin

I know the solution; either install therubyracer or nodejs gems.

try,   bundle install --without assets

If I install this in a production environment server, I do not need either one of these. And my browser definitely interprets javascript built in. So how does this fit in to everything? Is my premise incorrect?

you are correct.

kind regards -botp

node-js is both both google V8 javascript engine plus some libraries (much as for example ruby is the ruby interpreter plus a bunch of standard library stuff)

Fred

Thank you, everyone. This was an issue only in my Fedora laptop. In my OSX, not a problem at all. I knew all along that installing therubyracer or nodejs would fix this, I just didn’t know the “why” since I thought these weren’t javascript interpreters; that they themselves were written in javascript that required a javascript interpreter.

That said, I installed therubyracer and I did see libv8 being installed along with it. This I believe is the javascript interpreter so it now makes sense and I understand that it is used only for compiling the assets in asset pipeline. Thanks again for everyone’s input.

p

I hate to add to the confusion, but therubyracer is now not recommended on Heroku. What do you suggest we do ? I typically precompile assets and push it. Is this the recommended way?

https://devcenter.heroku.com/articles/rails-asset-pipeline