找不到JavaScript运行环境。请访问https://github.com/sstephenson/execjs了解可用的运行环境列表。

6

我遇到了一个与Rails 4.1.7、Phusion Passenger版本4.0.53和nginx/1.6.2在Ubuntu服务器14.04 AWS实例上相关的问题,但使用rails server却可以正常工作。

错误日志:

App 2029 stdout: App 2029 stderr: sh: 1: App 2029 stderr: env: not found。App 2029 stderr: [ 2014-11-12 16:12:26.1580 1979/7feff83f9700 Pool2/Implementation.cpp:287 ]:无法生成应用程序 /home/ubuntu/apps/doger 的进程:启动预加载器时发生错误。错误 ID:b7381860。错误详细信息保存在:/tmp/passenger-error-SUjzpL.html。应用程序消息:找不到 JavaScript 运行时。有关可用运行时的列表,请参见 https://github.com/sstephenson/execjs。(ExecJS::RuntimeUnavailable)。 /var/lib/gems/1.9.1/gems/execjs-2.2.2/lib/execjs/runtimes.rb:51:in autodetect /var/lib/gems/1.9.1/gems/execjs-2.2.2/lib/execjs.rb:5:in /var/lib/gems/1.9.1/gems/execjs-2.2.2/lib/execjs.rb:4:in <top (required)> /var/lib/gems/1.9.1/gems/uglifier-2.5.3/lib/uglifier.rb:3:in require /var/lib/gems/1.9.1/gems/uglifier-2.5.3/lib/uglifier.rb:3:in <top (required)> /var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler/runtime.rb:76:in require /var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler/runtime.rb:76:in block (2 levels) in require /var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler/runtime.rb:72:in each /var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler/runtime.rb:72:in block in require /var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler/runtime.rb:61:in each /var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler/runtime.rb:61:in require /var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler.rb:133:in require /home/ubuntu/apps/doger/config/application.rb:7:in <top (required)> /home/ubuntu/apps/doger/config/environment.rb:2:in require /home/ubuntu/apps/doger/config/environment.rb:2:in <top (required)> config.ru:3:in require config.ru:3:in block in <main> /usr/lib/ruby/vendor_ruby/rack/builder.rb:55:in instance_eval /usr/lib/ruby/vendor_ruby/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 /usr/share/passenger/helper-scripts/rack-preloader.rb:29 <module:PhusionPassenger> /usr/share/passenger/helper-scripts/rack-preloader.rb:28
GemFile
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.7'
# Use postgresql as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
#gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',        group: :development

我已经安装了nodejs(v0.10.25)

3个回答

17

每次我设置一个新的Ubuntu / Nginx / Passenger / Rails服务器时,都会遇到这个问题。尝试以下操作:

首先安装Node:

sudo apt-get install nodejs

然后像这样将您的路径环境添加到/etc/nginx/nginx.conf中:

env PATH;

或者更具体地说(如果node位于/usr/bin/nodejs):

env PATH=/bin:/usr/bin;


1
有没有更具体的方法,而不是将整个 PATH 暴露给 nginx? - Ludovic Kuty

4
取消注释带有“therubyracer”宝石的行,如下所示:
gem 'therubyracer',  platforms: :ruby

并运行bundle install。我希望这可以帮助你。


OP 应该使用系统范围内安装的 nodejs,而不是 therubyracer。 - Ludovic Kuty

0

我曾经遇到过类似的问题,而且我的机器上已经运行了nodejs。在经过所有的查找之后,我才意识到需要在我的Gemfile中包含execjs gem:

gem "execjs", "~> 2.8.1"

然后运行bundle install


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接