Skip to content

Add therubyracer/therubyrhino to Gemfile when there isn't a JS Runtime available in the system - #3619

Closed
guilleiguaran wants to merge 1 commit into
rails:masterfrom
guilleiguaran:js-runtime-in-gemfile
Closed

guilleiguaran wants to merge 1 commit into
rails:masterfrom
guilleiguaran:js-runtime-in-gemfile

Conversation

@guilleiguaran

Copy link
Copy Markdown
Member

This will make the apps usable by default for all Linux users that don't have Node.js installed in the system. (There are a lot of users). See #2963 for details.

Additionally if JRuby is detected therubyrhino is added by default

@wycats

wycats commented Nov 12, 2011

Copy link
Copy Markdown
Member

Since the Gemfile is created during the development environment only, and development environments aren't always the same as production environments, I think this should go in the development group.

Thoughts?

@jonleighton

Copy link
Copy Markdown
Member

GNOME 3 ships with SpiderMonkey, so it would be good to detect that (which js) too.

@josevalim

Copy link
Copy Markdown
Contributor

This is already getting too complicated. I am more in favor of execjs raising a meaningful error message (if it doesn't yet).

@jonleighton

Copy link
Copy Markdown
Member

Yeah, I agree with that.

@guilleiguaran

Copy link
Copy Markdown
Member Author

The error message in execjs looks fine for me but looks like some new users don't found it very friendly since they are following the Getting Started Guide and they expect having working apps by default.

Actually the purpose of running bundle in new generated apps is have working apps immediately, and in this case the users will have to edit their Gemfile and run bundle a second time just to see the "Welcome aboard" page.

@guilleiguaran

Copy link
Copy Markdown
Member Author

About JRuby, I think it's a different case, therubyrhino is the best default for JRuby in 100% of cases and the JRuby team was planning already send a patch about this, I will create a separated Pull Request for it

@vijaydev

Copy link
Copy Markdown
Member

I would suggest we pick one option (therubyracer ?) and put that in the Gemfile without trying to guess the right choice for the user thereby avoiding complications. Let the user choose something else if need be, and we can have a comment indicating so.

@wsouto

wsouto commented Nov 13, 2011

Copy link
Copy Markdown

I'm more on @josevalim's suggestion. A nice and meaningful message from ExecJS can be suffice for anyone to decide in which way they want to handle the situation: by putting the gem on Gemfile or installing node. But I see the @guilleiguaran's point of having a working app in no time. I saw myself in that situation a few times on Linux. So, can I suggest something like this in case you go this way:

if RUBY_PLATFORM.include? "linux"
  # put therubyracer/therubyrhino here
end

So it will not cause the gem to be installed in a Mac when an app has started on a Linux machine without any JS runtime, which could be a quite common scenario.

A message from ExecJS + the @vijaydev's suggestion of a comment in Gemfile can be nice too. I like this way.

@jonleighton

Copy link
Copy Markdown
Member

The thing is, therubyracer takes forever to install. If I am on ubuntu, I'd much rather try to start my app, have that fail, type "sudo apt-get install nodejs", and then succeed, than wait like 10-20 minutes for therubyracer to compile.

@guilleiguaran

Copy link
Copy Markdown
Member Author

@jonleighton agree, therubyracer compiling time was improved with 0.9.x release but still taking minutes to install. On my machine (Macbook Air) it takes 4 minutes to install.

Maybe we can improve the error message in execjs giving posible hints directly in the error message (like add therubyracer to the Gemfile or install Node.js)

@jonleighton

Copy link
Copy Markdown
Member

Improving the execjs errors sounds good to me. Closing this here then.

@danielvlopes

Copy link
Copy Markdown
Contributor

Sorry, but improve the error message will not help. In last two months, I had more than a hundred of new students for Rails 3.1 and I answered, at least, 10 times what is a javascript runtime and why they need install it.

For us it's natural but for somebody that probably never opened the terminal it's not (and execjs's message is already good enough when you know what execjs is).

@jonleighton

Copy link
Copy Markdown
Member

Perhaps you guys can start a discussion on the Rails core mailing list if you still want to pursue this? There are clearly some different views so would be good to get more discussion of it.

@danielvlopes

Copy link
Copy Markdown
Contributor

I just sent a msg in Rails core but we need to wait for the moderation.

@josevalim

Copy link
Copy Markdown
Contributor

I am fine with a solution along those lines of the logic is not implemented by Rails. If we could ask exec.js if there is a runtime available and if not, fallback to therubyracer, that would be fine for me. If not, totally -1 for rails checking node, spider monkey versions and etc.

@guilleiguaran

Copy link
Copy Markdown
Member Author

@josevalim We can ask to ExecJS if there is a engine available but we will need make to execjs gem a dependency for railties

@josevalim

Copy link
Copy Markdown
Contributor

Damn, I missed this detail. So the feature is a -1 on my side.

@jrochkind

Copy link
Copy Markdown
Contributor

I think it's really unfortunate that currently on Linux systems rails new gets you an app that results in an error message, rather than a working app. Pre-asset-pipeline, rails new (or 2.x rails app_name) always got you an app that would boot (thanks to sqlite3, among other things).

It's really unfortunate that this is no longer true, and is definitely a poor and discouraging experience for newbies -- the error message does not keep it from being so.

I'd agree that the 'right' way to handle this would be to make 'execjs' a dependency of railties, and then have the generator use execjs's own logic to determine if a ruby runtime is avail, rather than duplicating execjs logic in Rails generator. (ExecJS::Runtimes.autodetect and rescue RuntimeUnavailable).

execjs is a pretty small and pure ruby gem, it doesn't seem that bad to add it as a dependency.

The 'expert' user can install node.js on their system, and then execjs will detect it and therubyracer will never be added to their Gemfile. But for non-expert/newbie users, things should Just Work, even at the cost of a longer 'bundle install' to build therubyracer.

@brentsowers1

Copy link
Copy Markdown

Pull Request 4407 (#4407): This is the same change as 4405, just in the 3.1 branch. tenderlove responded to it and I replied. I totally agree with @jrochkind, it's unfortunate that rails new will not generate a runnable app. A total newbie's first impression with Rails shouldn't be frustration that it didn't work out of the box when getting up and running quickly has always been a great feature of Rails, especially when the problem can be easily solved and has already been written. I'm sure once a new user figures out how to add therubyracer to Gemfile, they'll think the same thing I did when this error happened to me, "Why didn't Rails do this? It added all of those other gems to the Gemfile".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants