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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12520456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 10:36:15  来源:igfitidea点击:

ExecJS::RuntimeError on Windows trying to follow rubytutorial

javascriptruby-on-railsrubywindowsasset-pipeline

提问by user1687078

UPDATE:Colin's suggestion of removing the line //= require_tree . has fixed the issue.

更新:Colin建议删除该行 //= require_tree 。已经解决了这个问题。

I have wasted over 2 days trying to follow every suggestion out there and fix my issue. I am trying to follow the http://ruby.railstutorial.orgbook on windows machine and cannot for the life of me get past the following nasty error.

我浪费了超过 2 天的时间试图遵循那里的每一个建议并解决我的问题。我正在尝试在 Windows 机器上遵循http://ruby.railstutorial.org 的书,但我一生都无法克服以下令人讨厌的错误。

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

I have tried every suggestion including installing nodejs with the msi, using execjs 1.3.0 and other things which I can't even remember any more. Here is the gem file

我已经尝试了所有建议,包括使用 msi 安装 nodejs、使用 execjs 1.3.0 和其他我什至不记得的东西。这是宝石文件

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

and here is the sessions.js.coffee

这是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

应用程序.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

应用程序.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>

Here is console content

这是控制台内容

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)

I have installed Devkit and have tried various gems but please suggest changes which can help me develop on windows. I used rubyinstaller for everything.

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

What am I missing?

我错过了什么?

回答by Kevin P

My friend was attempting a Rails tutorial on Win 8 RTM a few months ago and ran into this error. Not sure if this issue exists in Windows 7 as well, but this may help.

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

Options:

选项:

1) Removing //= require_tree ./ Ignoring the issue -As ColinR stated above, this line should not be causing an issue in the first place. There is an actual problem with ExecJS working properly with the JavaScript runtime on your system and removing this line is just ignoring that fact.

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

2) Installing Node.js / Running away -Many people seem to just end up installing Node.js and using that instead of the JavaScript runtime already on their system. While that is a valid option, it also requires additional software and only avoids the original issue, which is that ExecJS is not working properly with the JavaScript runtime already on your system. If the existing JavaScript runtime on your system is supposed to work, why not make it work instead of installing more software? According to the ExecJS creator, the runtime already built into Windows is in fact supported...

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 )

ExecJS 允许您从 Ruby 运行 JavaScript 代码。它会自动选择可用的最佳运行时来评估您的 JavaScript 程序,然后将结果作为 Ruby 对象返回给您。

ExecJS 支持这些运行时:

  • therubyracer - 嵌入在 Ruby 中的 Google V8
  • therubyrhino - 嵌入在 JRuby 中的 Mozilla Rhino
  • 节点.js
  • Apple JavaScriptCore - 包含在 Mac OS X 中
  • Microsoft Windows 脚本宿主 (JScript)

(来自 github.com/sstephenson/execjs#execjs )

3) Actually fixing the issue / Learning -Use the knowledge of options 1 and 2 to search for other solutions. I can't tell you how many webpages I closed upon seeing options 1 or 2 was the accepted solution before actually finding information about the root issue we were having. The only reason we kept looking was that we couldn't believe the Rails team would (1) insert a line of code in every scaffold generated project that caused an issue, or (2) require that we install additional software just to run that default line of code. And so we eventually arrived at a fix for our root issue (your miles may vary).

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

The Fix that worked for us:On the system having issues, find ExecJS's runtimes.rbfile. It looks like this. Make a copy of the found file for backup. Open the original runtimes.rb for editing. Find the section that starts with the line JScript = ExternalRuntime.new(. In that section, on the line containing :command => "cscript //E:jscript //Nologo //U",- remove the //Uonly. Then on the line containing :encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE- change UTF-16LE to UTF-8. Save the changes to the file. This section of the file should now read:

对我们有用的修复:在有问题的系统上,找到 ExecJS 的runtimes.rb文件。看起来像这样。复制找到的文件以进行备份。打开原始 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
)

Next, stop then restart your Rails server and refresh the page in your browser that produced the original error. Hopefully the page loads without error now. Here's the ExecJS issue thread where we originally posted our results: https://github.com/sstephenson/execjs/issues/81#issuecomment-9892952

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

If this did not fix the issue, you can always overwrite the modified runtimes.rb with the backup copy you (hopefully) made and everything will be back to square one. In that case, consider option 3 and keep searching. Let us know what eventually works for you.. unless it's removing the require_tree or installing node.js, there's plenty of that going around already. :)

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

回答by snassr

Had the same issue OS- Windows 8 Error- 'ExecJS::RuntimeError...' Solution- missing Node.js

有同样的问题 OS-Windows 8 错误-'ExecJS::RuntimeError...' 解决方案-缺少 Node.js

  1. install Node.js from http://www.nodejs.org/download/
  2. Restart the computer
  1. http://www.nodejs.org/download/安装 Node.js
  2. 重新启动计算机

回答by gustavoanalytics

I had this problem and was scowering the internet I am running Windows 8 with this rails gem file

我遇到了这个问题并且正在上网 我正在使用这个 rails gem 文件运行 Windows 8

source 'https://rubygems.org'

gem 'rails', '3.2.9'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

group :development do gem 'sqlite3', '1.3.5' 
end

# Gems used only for assets and not required # in production environments by default. 

group :assets do 
    gem 'sass-rails', '3.2.5' 
    gem 'coffee-rails', '3.2.2'

gem 'uglifier', '1.2.3' 
end

gem 'jquery-rails', '2.0.2'

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

Went to http://nodejs.org/download/installed - restarted the machine and everything worked.

http://nodejs.org/download/安装 - 重新启动机器,一切正常。

回答by cofiem

I favoured the Learningroute. It seems the problem stems from

我喜欢学习路线。似乎问题源于

IO.popen(command, options) { |f| output = f.read }

returning an empty string in execjs\external_runtine.rb(line 173 in version 1.4.0). This is why the error message contains no text. The changes suggested did not work for me. I changed UTF-16LEto UTF-8, but it still returned an empty string. I removed \\Ufrom the command- this at least returned text, but it was in the wrong encoding - in the browser it displayed as Chinese characters.

execjs\external_runtine.rb(版本 1.4.0 中的第 173 行)中返回一个空字符串。这就是错误消息不包含文本的原因。建议的更改对我不起作用。我换UTF-16LEUTF-8,但它仍然返回一个空字符串。我\\Ucommand- 这至少返回了文本,但它的编码错误 - 在浏览器中它显示为中文字符。

According to this MSDN blog post, using the //Uflag and redirecting to a file causes cscriptto return the result using UTF-16.

根据这篇 MSDN 博客文章,使用该//U标志并重定向到文件会cscript导致使用UTF-16.

And then, magically, it worked (@#%$&^@$%!!!?!?!) using commandas "cscript //E:jscript //Nologo"and encodingas "UTF-8". Oh well.

然后,神奇的是,它使用as和as有效(@#%$&^@$%!!!?!?!)。那好吧。command"cscript //E:jscript //Nologo"encoding"UTF-8"

回答by Dinuz

I know this is a very late answer for this issue, but I got on something similar and went down the full path to understand what was really causing the issue.

我知道这是对这个问题的一个很晚的答案,但我遇到了类似的问题,并沿着完整路径了解了真正导致问题的原因。

Turned out that the default windows jscript engine is still on es3, and many gems are taking advantage of es5 or es6 features. Unfortunately if this happen (you are using a gem or a piece of code that leverage es5 or es6 features), there is no way to let it work on windows with the native js engine.

原来windows默认的jscript引擎还在es3上,很多gem都在利用es5或者es6的特性。不幸的是,如果发生这种情况(您正在使用 gem 或利用 es5 或 es6 功能的一段代码),则无法让它在具有本机 js 引擎的 Windows 上工作。

This is the reason why installing node.js solves the problem (node is at least es5).

这就是安装node.js解决问题的原因(node至少是es5)。

Hope this can help some folks struggling with a runtime error of jsexec.

希望这可以帮助一些人在 jsexec 的运行时错误中苦苦挣扎。

My 2 cents advise is to install node(very easy) or install v8, and not removing the //=require_tree.

我的 2 美分建议是安装节点(非常简单)或安装 v8,而不是删除 //=require_tree。

Note execjs will automatically use node if detected. Otherwise force its use, adding in boot something like:

请注意,如果检测到 execjs 将自动使用节点。否则强制使用它,在引导中添加如下内容:

ENV['EXECJS_RUNTIME'] = 'Node'

To set the env to node.

将环境设置为节点。

回答by Evan

I had to add my nodejs folder to my Windows Path environment variable. In Windows 8 open the Control Panel, go to System, Advanced system settings (on the left), click Environment Variables on the left, and edit the Path variable to include the directory to your nodejs folder (probably in Program Files).

我必须将我的 nodejs 文件夹添加到我的 Windows Path 环境变量中。在 Windows 8 中,打开控制面板,转到系统、高级系统设置(左侧),单击左侧的环境变量,然后编辑 Path 变量以将目录包含到您的 nodejs 文件夹中(可能在 Program Files 中)。

Of course you have to have Node.js installed (use the Windows installer) and have installed CoffeeScript through NPM.

当然,您必须安装 Node.js(使用Windows 安装程序)并通过 NPM 安装 CoffeeScript。

回答by DJSampat

For windows users, this may work. There is a problem with coffee-script-source >1.9.0 running on windows.

对于 Windows 用户,这可能有效。在 windows 上运行的 coffee-script-source >1.9.0 有问题。

It seems you have to add this to your gemfile:

看来您必须将其添加到您的 gemfile 中:

gem 'coffee-script-source', '1.8.0'

宝石“咖啡脚本源”,“1.8.0”

then do

然后做

bundle update coffee-script-source

捆绑更新咖啡脚本源

I tried all the above options, and also mixed up a few combinations of them, till I found this Rails-4, ExecJS::ProgramError in Pages#welcomeand had done multiple system gem updates and bundle installs and updates.

我尝试了上述所有选项,并混合了它们的一些组合,直到我在 Pages#welcome 中找到了这个Rails-4、ExecJS::ProgramError并完成了多个系统 gem 更新以及捆绑安装和更新。

I reverted all my trials and downgraded my coffee-script-source and it works. Posting here to help out anyone else, who may have a similar issue.

我恢复了我所有的试验并降级了我的咖啡脚本源,它可以工作。在这里发帖是为了帮助其他可能有类似问题的人。

Updating files in vendor/cache

更新供应商/缓存中的文件

coffee-script-source-1.8.0.gem Removing outdated .gem files from vendor/cache coffee-script-source-1.9.1.1.gem Bundle updated!

coffee-script-source-1.8.0.gem 从供应商/缓存中删除过时的 .gem 文件 coffee-script-source-1.9.1.1.gem 包更新!

回答by Leandro P.

For beginners like me:

对于像我这样的初学者:

  1. Navigate to \app\views\layouts\application.html.erb
  2. Change line 6 from:

    '<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>'

  1. 导航到 \app\views\layouts\application.html.erb
  2. 将第 6 行从:

    '<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>'

to

<%= javascript_include_tag 'defaults', 'data-turbolinks-track' => true %>

Source from tutorial to fix here

来自教程的来源在这里修复

回答by Colin R

Quick and dirty solution: remove //= require_tree .from application.js.

快速而肮脏的解决方案://= require_tree .application.js.

As I explain in the comments for the question, this doesn't actually solve the underlying issue that is causing the error, but merely sidesteps it.

正如我在问题的评论中所解释的那样,这实际上并没有解决导致错误的潜在问题,而只是回避了它。

回答by Yuliem Alavez

I used the solution number 2 because previously i had have this mistake, but in this ocation didn't work, then I added the

我使用了解决方案 2,因为以前我有这个错误,但在这个位置不起作用,然后我添加了

gem 'coffee-script-source', '1.8.0'

gem 'coffee-script-source', '1.8.0'

and run

并运行

bundle install

and my problem was fixed

我的问题得到了解决