javascript - Windows 上的 ExecJS::RuntimeError 试图遵循 ruby​​tutorial

标签 javascript ruby-on-rails ruby windows asset-pipeline

更新: Colin删除行的建议//= require_tree 。已解决问题。

我已经浪费了 2 天多的时间来尝试遵循那里的每一个建议并解决我的问题。我正在尝试关注 http://ruby.railstutorial.org在 Windows 机器上预订,我终生无法克服以下严重错误。

ExecJS::RuntimeError in Static_pages#home

Showing C:/Users/.../bootcamp-sample-app/app/views/layouts/application.html.erb where line #6 raised:

["ok","(function() {\n\n\n\n}).call(this);\n"]
(in C:/Users/.../bootcamp-sample-app/app/assets/javascripts/sessions.js.coffee)
Extracted source (around line #6):

3: <head>
4:   <title><%= full_title(yield(:title)) %></title>
5:   <%= stylesheet_link_tag    "application", media: "all" %>
6:   <%= javascript_include_tag "application" %>
7:   <%= csrf_meta_tags %>
8:   <%= render 'layouts/shim' %>
9: </head>
Rails.root: C:/Users/.../bootcamp-sample-app

Application Trace | Framework Trace | Full Trace
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___487732698_30422172'
Request

我已经尝试了每一个建议,包括使用 msi 安装 nodejs,使用 execjs 1.3.0 和其他我什至不记得的东西。这是gem文件

source 'https://rubygems.org'

gem 'rails', '3.2.8'
gem 'bootstrap-sass', '2.0.0'
gem 'bcrypt-ruby', '3.0.1'
gem 'faker', '1.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'

group :development, :test do
  gem 'sqlite3', '1.3.5'
  gem 'rspec-rails', '2.10.0'
  gem 'guard-rspec', '0.5.5'
  gem 'guard-cucumber'
end

group :development do
  gem 'annotate', '2.5.0'
end


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'coffee-script'
  gem 'uglifier'
end

gem 'jquery-rails', '2.0.2'

gem 'execjs'

# Gems on Linus/Mac
#gem 'therubyracer'


group :test do
  gem 'capybara', '1.1.2'
  gem 'guard-spork', '0.3.2'
  gem 'spork', '0.9.0'
  gem 'factory_girl_rails', '1.4.0'
  gem 'cucumber-rails', '1.2.1', require: false
  gem 'database_cleaner', '0.7.0'


# Test gems on Linux
#  gem 'rb-inotify', '0.8.8'
#  gem 'libnotify', '0.5.9'

# Test gems on Macintosh OS X
#  gem 'selenium-webdriver', '~> 2.22.0'
#  gem 'rb-fsevent', '0.9.1', :require => false
#  gem 'growl', '1.0.3'

# Test gems on Windows
# gem 'rb-fchange', '0.0.5'
# gem 'rb-notifu', '0.0.4'
# gem 'win32console', '1.3.0'
end

group :production do
#  gem 'therubyracer'
  gem 'pg', '0.12.2'
end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
#gem 'debugger''

这是sessions.js.coffee

# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

application.js

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require bootstrap

application.html.erb

<!DOCTYPE html>
 <html>
 <head>
   <title><%= full_title(yield(:title)) %></title>
   <%= stylesheet_link_tag    "application", media: "all" %>
   <%= javascript_include_tag "application" %>
   <%= csrf_meta_tags %>
   <%= render 'layouts/shim' %>
 </head>
 <body>
 <%= render 'layouts/header' %>
 <div class="container">
   <%= yield %>
   <%= render 'layouts/footer' %>
 </div>
 </body>
 </html>

这是控制台内容

Processing by StaticPagesController#home as HTML
  Rendered static_pages/home.html.erb within layouts/application (45.0ms)
Completed 500 Internal Server Error in 1136ms

ActionView::Template::Error (["ok","(function() {\n\n\n\n}).call(this);\n"]
  (in C:/Users/.../bootcamp-sample-app/app/assets/javascripts/sessions.js.coffee)):
    3: <head>
    4:   <title><%= full_title(yield(:title)) %></title>
    5:   <%= stylesheet_link_tag    "application", media: "all" %>
    6:   <%= javascript_include_tag "application" %>
    7:   <%= csrf_meta_tags %>
    8:   <%= render 'layouts/shim' %>
    9: </head>
  app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___487732698_30422172'


  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.0ms)
  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (34.0ms)

我已经安装了 Devkit 并尝试了各种 gem,但请提出可以帮助我在 Windows 上开发的更改建议。我对一切都使用了 ruby​​installer。

我错过了什么?

最佳答案

几个月前,我的 friend 正在尝试在 Win 8 RTM 上学习 Rails 教程,但遇到了这个错误。不确定 Windows 7 中是否也存在此问题,但这可能会有所帮助。

选项:

1) 删除 //= require_tree ./Igning the issue - 正如 ColinR 上面所说,这一行不应该首先引起问题。 ExecJS 在您的系统上与 JavaScript 运行时正常工作存在实际问题,删除此行只是忽略了这一事实。

2) 安装 Node.js/逃跑 - 许多人似乎最终只是安装 Node.js 并使用它,而不是系统上已有的 JavaScript 运行时。虽然这是一个有效的选项,但它也需要额外的软件并且只能避免最初的问题,即 ExecJS 无法与系统上已有的 JavaScript 运行时一起正常工作。如果系统上现有的 JavaScript 运行时应该可以工作,为什么不让它工作而不是安装更多软件呢?根据 ExecJS 创建者的说法,Windows 中内置的运行时实际上是受支持的......

ExecJS lets you run JavaScript code from Ruby. It automatically picks the best runtime available to evaluate your JavaScript program, then returns the result to you as a Ruby object.

ExecJS supports these runtimes:

  • therubyracer - Google V8 embedded within Ruby
  • therubyrhino - Mozilla Rhino embedded within JRuby
  • Node.js
  • Apple JavaScriptCore - Included with Mac OS X
  • Microsoft Windows Script Host (JScript)

(from github.com/sstephenson/execjs#execjs )

3) 实际解决问题/学习 - 使用选项 1 和 2 的知识来搜索其他解决方案。在实际找到有关我们遇到的根本问题的信息之前,我无法告诉您我在看到选项 1 或 2 时关闭了多少网页是公认的解决方案。我们一直在寻找的唯一原因是我们无法相信 Rails 团队会 (1) 在每个脚手架生成的导致问题的项目中插入一行代码,或者 (2) 要求我们安装额外的软件来运行默认的代码行。因此,我们最终找到了解决根本问题的方法(您的里程可能会有所不同)。

对我们有用的修复: 在出现问题的系统上,找到 ExecJS 的 runtimes.rb 文件。看起来像 this .复制找到的文件进行备份。打开原来的 runtimes.rb 进行编辑。找到以 JScript = ExternalRuntime.new( 行开头的部分.在该部分中,包含 :command => "cscript //E:jscript //Nologo //U", 的行- 删除 //U只要。然后在包含 :encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE 的行上- 将 UTF-16LE 更改为 UTF-8 .保存对文件的更改。文件的这一部分现在应该是:

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
)

接下来,停止并重新启动您的 Rails 服务器,并在您的浏览器中刷新产生原始错误的页面。希望页面现在加载没有错误。这是我们最初发布结果的 ExecJS 问题线程:https://github.com/sstephenson/execjs/issues/81#issuecomment-9892952

如果这不能解决问题,您可以随时用您(希望)制作的备份副本覆盖修改后的 runtimes.rb,一切都会回到原点。在这种情况下,请考虑选项 3 并继续搜索。让我们知道最终对您有用的是什么……除非是删除 require_tree 或安装 node.js,否则已经有很多这样的方法了。 :)

关于javascript - Windows 上的 ExecJS::RuntimeError 试图遵循 ruby​​tutorial,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12520456/

相关文章:

javascript - 为什么这个 javascript 会因内存使用而导致浏览器崩溃?

javascript - 如何正确unminify js和css,并在html5中引用它们?

ruby-on-rails - 创建自定义 rspec 变量,如 Controller 规范的响应

ruby-on-rails - 通过渲染传递变量

ruby-on-rails - rails 3.2.x 到 rails 4.2 升级 : HTTP_COOKIE issue in request

javascript - sigma.js 中的自定义行为

javascript - 我可以从 mvc 中的一个操作方法一次返回两个结果吗?

ruby-on-rails - Rails SMTP 错误

ruby-on-rails - 在 Rails 应用程序中本地使用 gem 而不修改 Gemfile

ruby - 迭代字符串数组并执行正则表达式