Skip to content

Missing js runtime fix 3 1 stable - #4407

Closed
brentsowers1 wants to merge 1 commit into
rails:3-1-stablefrom
brentsowers1:missing_js_runtime_fix-3_1_stable
Closed

brentsowers1 wants to merge 1 commit into
rails:3-1-stablefrom
brentsowers1:missing_js_runtime_fix-3_1_stable

Conversation

@brentsowers1

Copy link
Copy Markdown

... a Javascript runtime (Linux without node js). Without this gem an error is reported by execjs

Issues #412 and #4020

I've tested this on Ubuntu with and without nodejs, and on Windows, and it works correctly, the Gemfile contains a line for therubyracer only on Ubuntu without nodejs

…ave a Javascript runtime (Linux without node js). Without this gem an error is reported by execjs
@tenderlove

Copy link
Copy Markdown
Member

I'd rather not have Rails do JavaScript runtime detection, especially since this is for envjs functionality. Rather than doing runtime detection, can we just add comments to the generated gemfile that tell the user what to do depending on their OS?

@brentsowers1

Copy link
Copy Markdown
Author

I agree that having to do the runtime detection in the Rails generator script is not ideal. But as it stands now, a newly created Rails project will not run on Linux (unless they've previously installed node.js) without the user having to look at the error message, go to the URL in the execjs error message, and install one of the gems listed there. This is not a problem for anyone in here looking at the Rails source code, but this is going to be one more roadblock for users totally new to Rails, who at this point are probably thinking "Rails was supposed to be easy to get up and running!". They're probably already overwhelmed by bundle, rake, and rails. This is one more thing to confuse them. If they do actually want to get it running, they're going to have to decide from the list of 6 things on that list. I imagine they won't want to install node.js, or Spidermonkey, I know when I first ran in to this I was a little offended that I might have to install node.js for something in Rails. So they'll want to go the gem route, but then, they have to decide on which one. Then, they'll have to at least get some idea of how gems work, and then learn a little about bundler and how to add gems to the Gemfile. And this will be the users very first impression of actually using Rails. To me this is too much to ask when it can all be solved by simply checking if one of the executables is on the system in Rails.

And I understand being concerned about solving essentially an execjs problem in Rails. However Rails requires execjs, so an execjs problem is essentially a Rails problem.

@jrochkind

Copy link
Copy Markdown
Contributor

Actually, technically, rails does not require execjs (execjs is not a dependency, direct or indirect, of the Rails gem), although Rails new app generator generates a local app Gemfile that, by default, does depend (indirectly) on execjs. It is theoretically possible to use Rails without execjs though (without the asset pipeline).

However, @tenderlove . I agree that Rails having to detect JS runtime, duplicating execjs code, is unfortunate. What do you think about actually making execjs a dependency of railties -- then the generator would be able to ask ExecJS::Runtimes.autodetect, instead of having to duplicate that code itself.

The downside is another dependency (that isn't actually used for anything BUT this in Rails code proper); however, execjs is a pretty small, simple, and pure ruby gem. And the way to be sure if execjs will find a runtime is, well, to ask execjs, rather than try to execute seperate logic that one hopes will decide the same thing as (possibly future versions of) execjs. And as long as rails generator generates an app that needs execjs, the only way to get a 'rails new whatever' that can actually boot (like every newly generated rails app could before asset pipeline), is to check if execjs will find a runtime, and if not add therubyracer (or equivalent) to Gemfile.

@tenderlove

Copy link
Copy Markdown
Member

Could we just do platform detection and emit "good defaults" depending on the platform? That would let us avoid runtime detection.

@jrochkind

Copy link
Copy Markdown
Contributor

@tenderlove that seems reasonable, although not as reliable. The idea
would be as-is on Windows and OSX, gem 'therubyracer' on everything
else?

This could make a mistake -- someone on Win or OSX might not actually
have a JS runtime that execjs can find for some odd reason. But that's
neccesarily so bad a 'failure mode'.

Worse, someone on linux might have node.js installed and not need
therubyracer, but the generator will add it to gemfile anyway, making
them wait through the too-lengthy bundle install and compilation for
it before they even have the chance to go and remove it from their
Gemfile (if they're smart enough to not need it). Which is def going
to annoy some 'power users'.

Using execjs seems the RIGHT way to do it, but the cost is a
dependency. Trade offs either way. Ultimately your call (or other
rails core team) I think, what do you think?

On Thu, Jan 12, 2012 at 12:41 PM, Aaron Patterson
[email protected]
wrote:

Could we just do platform detection and emit "good defaults" depending on the platform?  That would let us avoid runtime detection.


Reply to this email directly or view it on GitHub:
#4407 (comment)

@brentsowers1

Copy link
Copy Markdown
Author

I've issued a new pull request based on tenderlove's suggestion, #4436 (#4436)

@brentsowers1

Copy link
Copy Markdown
Author

I think it's fine to assume that Linux requires therubyracer, even if node.js is installed, good suggestion @tenderlove

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.

3 participants