【问题标题】:ExecJS::RuntimeUnavailable in Rails 4.1.4Rails 4.1.4 中的 ExecJS::RuntimeUnavailable
【发布时间】:2014-08-27 21:29:19
【问题描述】:

更新:现在一切正常!

感谢deep,我安装了node.js,然后得到了一个TZInfo::DataSourceNotFound 错误,通过添加gem 'tzinfo-data', platforms: [:mingw, :mswin]bundle update 得到了解决。

谢谢楼主!


首先,我是一个完整的 Rails 初学者(只是为了让您了解我是多么的初学者:我感觉自己是在这里发帖的专家),这是我在这里的第一个问题,如果我'我不是很清楚。

所以,我是 Windows 7 用户,正在通过一个月课程学习 rails,但在尝试时遇到错误:

$ 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)

$ 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>'

我所了解的只是 ExecJS 有问题。作为一个初学者,我什至不知道 ExecJS 是什么。

我阅读了很棒的帖子#12520456,虽然编辑 runtimes.rb 并没有解决我的问题,但它仍然让我更好地了解情况以及通过修复它而不是“忽略它”来解决我的问题的意愿通过添加 node.js 特别是考虑到我之前可以运行我的服务器并且我想修复我基本上破坏的问题。

我的意思是,我认为我在编辑 Windows 环境的 PATH(我什至不知道这是什么)以解决安装 Heroku 时遇到的问题时做错了。我记得我在某处读到它时编辑了那部分,虽然它似乎解决了我的 Heroku 问题,但我认为它搞砸了其余部分。

提前感谢您的帮助和理解。

【问题讨论】:

  • 我想解决这个问题的最好方法是安装一个像 node.js 这样的 js 运行时。
  • @deep :我可以试一试,由于我是一个初学者,请您指导我完成这些步骤吗?再次感谢
  • 确定您使用的是哪个操作系统?
  • 我使用的是 Windows 7 !

标签: javascript ruby-on-rails ruby windows execjs


【解决方案1】:

@KevinP here 已经详细回答了这个问题。

按照上面的链接,您需要进入 Execjs 的 runtimes.rb 并更改他的答案中指定的那一行。之后,重新启动您的服务器,它应该开始工作。

需要修改的块是这样的:

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
)

^ 归功于Kevin P

这几天我也回答了这个问题。 https://stackoverflow.com/a/24591983/2456549

【讨论】:

  • 你好贾斯汀,正如我在问题中所说,我已经通过了你指出的线程并且没有任何结果的 runtimes.rb 更改...我的错误消息是 ExecJS::RuntimeUnavailable 而不是ExecJS::RuntimeError 与其他线程一样。我不知道这是否会有所不同。
【解决方案2】:

一个快速简单的解决方案是在 Gemfile 中取消注释这一行并再次运行 bundle install

gem 'therubyracer',  platforms: :ruby

【讨论】:

  • 你好桑托什。该行不在我的 Gemfile 中(甚至没有评论),所以我手动添加了它并进行了捆绑安装,但我不断收到错误消息。
  • @Santosh ...好答案。但我有几个人得到这个错误。这个解决方案奇怪地只帮助解决了一些问题。
  • 不,Linux。确切地说是 Ubuntu。
  • 是的,我认为这就是原因。我相信上面的解决方案适用于我运行 linux 的虚拟机,但是当使用 Windows 时,唯一的解决方案是编辑 runtimes.rb 文件。 :)
  • 我使用的是 Windows 7,我尝试编辑 runtimes.rb 文件。 “路径”不是更多的问题吗?
【解决方案3】:

Ubuntu 用户

我在 Ubuntu 11.04 上遇到了类似的问题。安装 Node.js 修复了它。

从 Ubuntu 13.04 x64 开始,您只需要运行:

sudo apt-get install nodejs

这将解决问题。 CentOS/RedHat 用户

sudo yum install nodejs

【讨论】:

    【解决方案4】:

    根据@RedDeath 的回答,这是 Alpine 用户的最佳选择:

    apk add nodejs
    

    这为我解决了错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-24
      • 1970-01-01
      • 2015-04-09
      • 2018-04-10
      • 2012-05-05
      • 2015-03-30
      相关资源
      最近更新 更多