Rails/Passenger/Node.js:ExecJS“找不到JavaScript运行时"; [英] Rails/Passenger/Node.js: ExecJS "Could not find a JavaScript runtime"

查看:84
本文介绍了Rails/Passenger/Node.js:ExecJS“找不到JavaScript运行时";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Node.js用作我的Rails应用程序的JavaScript运行时.我在Nginx上使用Phusion Passenger模块作为Ubuntu 12.0.4上的Web服务器.每次我访问Rails应用程序时,都会显示一个错误页面,该错误页面似乎是由Passenger生成的,指出ExecJS找不到JavaScript运行时.我在这里看到了很多帖子,它们要么建议您安装Node(通过sudo apt-get install node完成),要么建议在Gemfile中使用therubyracer + execjs.后一种解决方案实际上确实有效,但是我真的更喜欢使用Node,尤其是因为已经声明了Heroku a>他们不鼓励使用therubyracer,因为它使用了大量内存".

I'm trying to use Node.js as the JavaScript runtime for my Rails application. I'm using the Phusion Passenger module with Nginx as my web server on Ubuntu 12.0.4. Every time I visit my Rails application I get an error page that appears to be generated from Passenger stating that ExecJS can't find a JavaScript runtime. I've seen numerous posts on here that either suggest that you install Node--which I have done via sudo apt-get install node--or suggest using therubyracer + execjs in your Gemfile. That latter solution does in fact work, but I would really prefer to use Node, especially since Heroku has stated that they discourage the use of therubyracer do to the fact that it uses a "very large amount of memory".

我遇到了教程,这表明运行我的Web服务器的用户的路径中可能没有Node.我通过运行sudo -u www-data which node进行了检查,它返回了/usr/bin/node.用户www-data是nginx运行时所用的用户,并且是拥有我的Rails应用程序中所有文件的用户.我还查看了/etc/environment,并且可以看到/usr/bin在系统范围的路径中.运行sudo -u www-data node -v还会返回预期的Node版本,因此它是可执行的.

I ran into a tutorial which suggests that the user that my web server runs as may not have Node in it's path. I checked this out by running sudo -u www-data which node and it returns /usr/bin/node. The user www-data is the user that nginx runs as, and the user that owns all the files in my Rails application. I've also looked at /etc/environment, and I can see that /usr/bin is in the system-wide path. Running sudo -u www-data node -v also returns the Node version as expected, so it is executable.

当我运行RAILS_ENV=production bundle exec rake assets:precompile时,没有任何错误.当我将ExecJS加载到与IRB的交互式会话中时,我能够使它返回有效的运行时.我还尝试过显式添加EXECJS_RUNTIME=Node作为环境变量,但是它只是说"Node.js(V8)运行时不可用".我已经尝试了很多事情,但我无法使它正常工作!

When I run RAILS_ENV=production bundle exec rake assets:precompile I don't get any errors. When I load ExecJS into an interactive session with IRB I'm able to get it to return a valid runtime. I've also tried explicitly adding EXECJS_RUNTIME=Node as an environment variable, but then it just says "Node.js (V8) runtime is not available" instead. I've tried many things and I just can't get this to work!

这是我访问Rails应用程序时遇到的错误.当我查看Nginx日志文件时,我看到的几乎是同一件事.

Here's the error I get when I visit my Rails app. When I look at the Nginx log file I see pretty much the same thing.

Web application could not be started

Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
  /usr/lib/ruby/gems/2.1.0/gems/execjs-2.0.2/lib/execjs/runtimes.rb:51:in `autodetect'
  /usr/lib/ruby/gems/2.1.0/gems/execjs-2.0.2/lib/execjs.rb:5:in `<module:ExecJS>'
  /usr/lib/ruby/gems/2.1.0/gems/execjs-2.0.2/lib/execjs.rb:4:in `<top (required)>'
  /usr/lib/ruby/gems/2.1.0/gems/uglifier-2.5.0/lib/uglifier.rb:3:in `require'
  /usr/lib/ruby/gems/2.1.0/gems/uglifier-2.5.0/lib/uglifier.rb:3:in `<top (required)>'
  /usr/lib/ruby/gems/2.1.0/gems/bundler-1.6.1/lib/bundler/runtime.rb:76:in `require'
  /usr/lib/ruby/gems/2.1.0/gems/bundler-1.6.1/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
  /usr/lib/ruby/gems/2.1.0/gems/bundler-1.6.1/lib/bundler/runtime.rb:72:in `each'
  /usr/lib/ruby/gems/2.1.0/gems/bundler-1.6.1/lib/bundler/runtime.rb:72:in `block in require'
  /usr/lib/ruby/gems/2.1.0/gems/bundler-1.6.1/lib/bundler/runtime.rb:61:in `each'
  /usr/lib/ruby/gems/2.1.0/gems/bundler-1.6.1/lib/bundler/runtime.rb:61:in `require'
  /usr/lib/ruby/gems/2.1.0/gems/bundler-1.6.1/lib/bundler.rb:132:in `require'
  /srv/www/app/config/application.rb:7:in `<top (required)>'
  /srv/www/app/config/environment.rb:2:in `require'
  /srv/www/app/config/environment.rb:2:in `<top (required)>'
  config.ru:3:in `require'
  config.ru:3:in `block in <main>'
  /usr/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
  /usr/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
  config.ru:1:in `new'
  config.ru:1:in `<main>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `eval'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `preload_app'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:158:in `<module:App>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'

推荐答案

我也遇到了这个问题.这就是为我解决的问题.我将此添加到了我的nginx.conf的顶部

I had this problem too. This is what fixed it for me. I added this to the top of my nginx.conf

env PATH;

http://wiki.nginx.org/CoreModule#env

当我认真研究此解决方案时,我还发现了这篇帖子,该帖子有助于我开始吠叫正确的树: https://forums.freebsd.org/viewtopic.php?&t=35539 ​​-他编辑execjs代码以提供指向node的绝对路径.这行之有效,并帮助我找到了如何为乘客提供通行之路.

As I zeroed in on this solution I also found this post which helped me start barking up the right tree: https://forums.freebsd.org/viewtopic.php?&t=35539 -- he edits the execjs code to give an absolute path to node. This worked and helped me find out how to give the path to passenger.

这篇关于Rails/Passenger/Node.js:ExecJS“找不到JavaScript运行时";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆