ExecJS::RuntimeUnavailable in Rails 4.1.4

2019-05-06 04:08发布

UPDATE : Things are now working !

Thanks to deep, I installed node.js then got a TZInfo::DataSourceNotFound error wich got resolved by adding gem 'tzinfo-data', platforms: [:mingw, :mswin] and bundle update.

Thank you sir !


First of all, I am a complete beginner on rails (just so that you get how beginner I am : I feel as being an expert for just posting here) and this is my first question here so please excuse me if I'm not very clear.

So, I am a windows 7 user, learning rails with the One Month course and I encounter an error while trying to :

$ rake routes
rake aborted!
ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://git
hub.com/sstephenson/execjs for a list of available runtimes.
c:/Users/Marc Montagne/Desktop/pinteresting/config/application.rb:7:in `<top (re
quired)>'
c:/Users/Marc Montagne/Desktop/pinteresting/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

or

$ rails server
c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/execjs-2.0.2/lib/execjs/run
times.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://gi
thub.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUn
available)
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/execjs-2.0.2/l
ib/execjs.rb:5:in `<module:ExecJS>'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/execjs-2.0.2/l
ib/execjs.rb:4:in `<top (required)>'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/uglifier-2.4.0
/lib/uglifier.rb:3:in `require'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/uglifier-2.4.0
/lib/uglifier.rb:3:in `<top (required)>'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:72:in `require'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:72:in `block (2 levels) in require'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:70:in `each'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:70:in `block in require'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:59:in `each'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler/runtime.rb:59:in `require'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/
lib/bundler.rb:132:in `require'
        from c:/Users/Marc Montagne/Desktop/pinteresting/config/application.rb:7
:in `<top (required)>'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:79:in `require'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:79:in `block in server'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:76:in `tap'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:76:in `server'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.4
/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
        from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.4
/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

All that I understand is that I have a problem with ExecJS. As a total beginner I don't even know what ExecJS is.

I read the great thread #12520456 and while editing runtimes.rb didn't fix my problem, it still gave me a better understanding of the situation and the willingness to solve my problem by fixing it and not "ignoring it" by adding node.js especially given the fact that I could run my server before and that I want to fix what I basically broke.

What I mean by that is that I think I did something wrong when editing the PATH (I don't even know what this is) of my Windows environment for fixing an issue I had with installing Heroku. I remember editing that part as I read it somewhere and while it seemed to have fixed my Heroku issue I think it messed up the rest.

Thank you in advance for your help and understanding.

3条回答
我欲成王,谁敢阻挡
2楼-- · 2019-05-06 04:44

A quick and easy solution is to uncomment this line in Gemfile and run bundle install again

gem 'therubyracer',  platforms: :ruby
查看更多
乱世女痞
3楼-- · 2019-05-06 04:47

This has been answered in great detail by @KevinP here.

Following the link above, you need to go into Execjs's runtimes.rb and change that line specified in his answer. After that, restart your server and it should start working.

The block that needs to be changed looks like this:

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
)

^ Credit to Kevin P.

I also answered this question a few days go here. https://stackoverflow.com/a/24591983/2456549

查看更多
做个烂人
4楼-- · 2019-05-06 04:52

Ubuntu Users

I'm on Ubuntu 11.04 and had similar issues. Installing Node.js fixed it.

As of Ubuntu 13.04 x64 you only need to run:

sudo apt-get install nodejs

This will solve the problem. CentOS/RedHat Users

sudo yum install nodejs
查看更多
登录 后发表回答