我正在尝试使用Mongoid/Devise Rails 3.1模板(Mongoid和Devise),并且我不断收到错误,指出ExecJS无法找到JavaScript运行时.当我没有安装任何东西时足够公平,但我已经尝试安装Node.js,Mustang和Ruby Racer,但没有任何工作.
我找不到JavaScript运行时.有关可用运行时()的列表,请参见sstephenson/ExecJS(GitHub ExecJS::RuntimeUnavailable).
为了让这个工作,我需要做什么?
我收到这个错误:
耙子流产了!找不到JavaScript运行时.请参阅https://github.com/sstephenson/execjs,
我已经花了更多时间搜索谷歌然后我愿意承认.我相信这是一个execJs的bug.
从所有帖子中,这是rails 3.1的一个非常常见的问题.现在需要一个js运行时现在标准的宝石如coffee-script和sass.
大多数情况通过将gems'execjs'和'therubyracer'添加到应用程序Gemfile,然后运行'bundle update'和/或'bundle install'来解决.但不适合我.
我想我很幸运.我在旧版本的Redhat Linux 4(2.6.9-101.ELsmp)上运行rails 3.1.3/ruby 1.9,gcc是3.4.6.
其他报告的修复没有帮助,我无法安装'nodejs','johnson'或'mustang',其他运行时execJs应该找到并使用.他们不会在我的系统上进行/安装.
我需要解决导致execJs无法找到'therubyracer'的问题.这是Gemfile(和bundle install说好):
source 'http://rubygems.org'
gem 'rails', '3.1.3'
gem 'sqlite3'
gem 'sho-mongrel'
gem 'execjs'
gem 'therubyracer'
#gem "therubyracer", :require => 'v8'
group :assets do
gem 'sass-rails', '~> 3.1.5'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
Run Code Online (Sandbox Code Playgroud)
这是一个痕迹:
~/rails/316-private-pub/chatter-after>rake db:create --trace
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs/runtimes.rb:50:in `autodetect'
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs.rb:5:in `<module:ExecJS>'
/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.3.0/lib/execjs.rb:4:in `<top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in …Run Code Online (Sandbox Code Playgroud) ruby-on-rails ruby-on-rails-plugins ruby-on-rails-3.1 execjs
启动一个新的应用程序,当我创建一个控制器页面回家并尝试转到本地主机:3000/pages/home时,我收到以下错误:
Showing c:/Users/Doesha/desktop/pinplug/app/views/layouts/application.html.erb where line #6 raised:
TypeError: Object doesn't support this property or method
(in c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee)
Run Code Online (Sandbox Code Playgroud)
application.html.erb文件:
<!DOCTYPE html>
<html>
<head>
<title>Pinplug</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
application_controller.rb文件:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
Run Code Online (Sandbox Code Playgroud)
pages_controller.rb文件:
class PagesController < …Run Code Online (Sandbox Code Playgroud) 部署我的Rails应用程序时,我收到以下错误:
rake aborted!
ExecJS::ProgramError: Unexpected token punc «(», expected punc «:» (line: 15, col: 14, pos: 265)
Error
at new JS_Parse_Error (/tmp/execjs20150524-4411-1p45n63js:2359:10623)
at js_error (/tmp/execjs20150524-4411-1p45n63js:2359:10842)
at croak (/tmp/execjs20150524-4411-1p45n63js:2359:19086)
at token_error (/tmp/execjs20150524-4411-1p45n63js:2359:19223)
at expect_token (/tmp/execjs20150524-4411-1p45n63js:2359:19446)
at expect (/tmp/execjs20150524-4411-1p45n63js:2359:19584)
at /tmp/execjs20150524-4411-1p45n63js:2359:28513
at /tmp/execjs20150524-4411-1p45n63js:2359:19957
at expr_atom (/tmp/execjs20150524-4411-1p45n63js:2359:27269)
at maybe_unary (/tmp/execjs20150524-4411-1p45n63js:2359:30019)new JS_Parse_Error ((execjs):2359:10623)
js_error ((execjs):2359:10842)
croak ((execjs):2359:19086)
token_error ((execjs):2359:19223)
expect_token ((execjs):2359:19446)
expect ((execjs):2359:19584)
(execjs):2359:28513
(execjs):2359:19957
expr_atom ((execjs):2359:27269)
maybe_unary ((execjs):2359:30019)
Run Code Online (Sandbox Code Playgroud)
有问题的文件是有效的,它适用于localhost.我也试过rake assests:precompile在localhost上运行,一切都通过了.最后,我试图从文件中删除内容,git push和redeploy - 仍然得到相同的错误.只有完全删除文件并重新部署帮助.
会欣赏任何想法.
我有一个rails应用程序,我想强制execjs用户Node.js作为javascript运行时.我如何检查哪些运行时execjs正在使用?
谢谢.
当尝试将rails 5应用程序部署到heroku时,我遇到以下错误Running: rake assets:precompile:
remote: ExecJS::ProgramError: SyntaxError: Unexpected token: name (autoRegisterNamespace) (line: 14767, col: 7, pos: 457487)
remote: Error
remote: at new JS_Parse_Error (<eval>:3623:11948)
remote: at js_error (<eval>:3623:12167)
remote: at croak (<eval>:3623:21858)
remote: at token_error (<eval>:3623:21995)
remote: at unexpected (<eval>:3623:22083)
remote: at semicolon (<eval>:3623:22601)
remote: at simple_statement (<eval>:3623:25779)
remote: at <eval>:3623:23567
remote: at <eval>:3623:22774
remote: at block_ (<eval>:3623:27903)
remote: at <eval>:3623:23677
remote: at <eval>:3623:22774
remote: new JS_Parse_Error ((execjs):3623:11948)
remote: js_error ((execjs):3623:12167)
remote: croak ((execjs):3623:21858)
remote: token_error ((execjs):3623:21995)
remote: …Run Code Online (Sandbox Code Playgroud) 有几种方法可以在Ruby脚本中运行JavaScript.例如,ExecJS经常用于将NPM模块移植到Ruby.那么,Node有"ExecRuby"吗?
在我的一个Rails应用程序中,ExecJS没有显示coffeescript编译错误的行号.我的编译错误消息将如下所示:
ExecJS::RuntimeError in Referrals#new
Showing ~/MyApp/app/views/layouts/application.html.erb where line #6 raised:
SyntaxError: unexpected IDENTIFIER
(in ~/MyApp/assets/javascripts/utils.js.coffee)
Run Code Online (Sandbox Code Playgroud)
请注意,咖啡脚本源没有行号(第6行用于erb文件).
在我的另一个应用程序中,我仍然在获取行号,语法错误如下所示:
ExecJS::ProgramError in Projects#show
Showing ~/OtherApp/app/views/layouts/application.html.erb where line #17 raised:
Error: Parse error on line 6: Unexpected 'STRING'
(in ~/OtherApp/app/assets/javascripts/projects.js.coffee)
Run Code Online (Sandbox Code Playgroud)
所以看起来不同的是,它ExecJS::ProgramError会给出行号,而ExecJS::RuntimeError不是.
任何人都知道如何获得行号?为什么我的应用程序在咖啡资产编译时创建RuntimeErrors,而另一个是给出ProgramErrors?我检查过Rails,它们似乎匹配.
请注意,如果我修复编译错误,应用程序运行正常(例如,咖啡文件实际上已经编译) - 但是让这些行号指向编译错误会很好!
编辑
我意识到无论是ExecJS Runtimeerror还是ProgramError似乎并不重要 - 在第一个应用程序中,从来没有给出行号,而在第二个应用程序中,总是有.
我有一个需要运行节点脚本的rails应用程序.我想使用ExecJS gem是从rails应用程序运行js最干净的方法.然而,到目前为止,ExecJS使用起来非常令人沮丧.
这是我需要运行的脚本:
// Generated by CoffeeScript 1.7.1
(function() {
var PDFDocument, doc, fs;
fs = require("fs");
PDFDocument = require('pdfkit');
doc = new PDFDocument;
doc.pipe(fs.createWriteStream('output.pdf'));
doc.addPage().fontSize(25).text('Here is some vector graphics...', 100, 100);
doc.save().moveTo(100, 150).lineTo(100, 250).lineTo(200, 250).fill("#FF3300");
doc.scale(0.6).translate(470, -380).path('M 250,75 L 323,301 131,161 369,161 177,301 z').fill('red', 'even-odd').restore();
doc.addPage().fillColor("blue").text('Here is a link!', 100, 100).underline(100, 100, 160, 27, {
color: "#0000FF"
}).link(100, 100, 160, 27, 'http://google.com/');
doc.end();
}).call(this)
Run Code Online (Sandbox Code Playgroud)
从我的rails控制台,我试试这个:
[2] pry(main)> file = File.open('test.js').read
[3] pry(main)> ExecJS.eval(file)
ExecJS::ProgramError: TypeError: undefined is not a …Run Code Online (Sandbox Code Playgroud) rake assets:precompile 我的rails项目抛出以下错误:
耙子流产了!当前的ExecJS运行时不支持ES6.请安装最新的Node.js.
以下是环境信息:
rails -v
Rails 5.0.7
ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
node -v
v6.11.1
Run Code Online (Sandbox Code Playgroud)
我尝试重新安装我的所有宝石.但是,错误仍然存在.操作系统是RHEL.
任何建议将不胜感激.
execjs ×10
javascript ×4
node.js ×3
ruby ×3
coffeescript ×1
deployment ×1
git ×1
heroku ×1
rake ×1
turbolinks ×1
uglifyjs ×1
windows ×1