将 Rails 3.1 项目部署到 Heroku 时出现问题:找不到 JavaScript 运行时 [英] Problem deploying Rails 3.1 project to Heroku: Could not find a JavaScript runtime

查看:19
本文介绍了将 Rails 3.1 项目部署到 Heroku 时出现问题:找不到 JavaScript 运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将 rails 3.1 beta 项目部署到 heroku 时遇到问题.问题发生在数据库迁移步骤.当我跑:

heroku rake db:migrate

我收到错误消息:

<前>> 耙子中止!> 找不到 JavaScript 运行时.看> https://github.com/sstephenson/execjs> 获取可用运行时的列表.>/app/Rakefile:5>(通过使用 --trace 运行任务查看完整跟踪)>(在/应用程序中)

但是我可以在本地成功运行该应用程序,并且我确实安装了 nodejs.知道为什么吗?

这是我的宝石清单:

抽象 (1.0.0)actionmailer (3.1.0.beta1)动作包(3.1.0.beta1、3.0.7)活动模型 (3.1.0.beta1, 3.0.7)activerecord (3.1.0.beta1)活动资​​源 (3.1.0.beta1)主动支持 (3.1.0.beta1, 3.0.7)安西 (1.2.5)海尔 (2.1.0)bcrypt-ruby (2.1.4)建造者 (3.0.0, 2.1.2)捆绑器 (1.0.13)咖啡脚本 (2.2.0)咖啡脚本源 (1.1.0)配置 (1.2.0)daemon_controller (0.2.6)erubis (2.7.0, 2.6.6)execjs (1.0.0, 0.3.3)快速线程 (1.0.7)Heroku (2.1.4)远足 (1.0.0)i18n (0.6.0beta1, 0.5.0)jquery-rails (1.0.1)json (1.5.1)json_pure (1.5.1)发射(0.4.0)邮件 (2.3.0)哑剧类型 (1.16)小测试 (1.6.0)multi_json (1.0.1)mysql (2.8.1)mysql2 (0.3.2)oauth (0.4.4)乘客 (3.0.7)多语言 (0.3.1)机架(1.3.0.beta,1.2.2)机架缓存 (1.0.1)机架安装(0.7.2、0.6.14)机架 SSL (1.3.2)机架测试 (0.6.0, 0.5.7)导轨 (3.1.0.beta1)导轨 (3.1.0.beta1)耙子 (0.8.7)文档 (2.5.8)休息客户端(1.6.1)rubygems 更新 (1.8.1)sass (3.1.1)simplegeo (0.5.1)链轮 (2.0.0.beta.2)sqlite3 (1.3.3)sqlite3-ruby (1.3.3)术语 ansicolor (1.0.5)therubyracer-heroku (0.8.1.pre3)雷神 (0.14.6)倾斜 (1.3)树梢 (1.4.9)转 (0.8.2)tzinfo (0.3.27)uglifier (0.5.1)

解决方案

你需要一个适用于 Rails 3.1 的 JavaScript 引擎(heroku 没有),而且看起来与 Heroku 一起工作的 JavaScript 引擎是 heroku 的 ruby​​racer.

Rails 使用 execjs 来执行 JavaScript,execjs 支持 7 个 JavaScript 引擎.Node.js 是其中之一,而 ruby​​racer 是其中之一.

Gerred Dillon 遇到了类似的问题并写了一篇文章.在评论部分中,有人提出要将此更改为仅用于生产的更改,因为您已经将 nodejs 作为本地 JavaScript 引擎.所以相关代码是:

group :production do宝石therubyracer-heroku",0.8.1.pre3"结尾

更新: Heroku 有一个新的堆栈,名为 Cedar,他们推荐用于 Rails 3.1.0.(运行 heroku stack 以查看您的应用程序所在的堆栈.)Heroku 还有一个 doc 关于升级到 Rails 3.1.0 rc5.他们建议不要再使用therubyracer-heroku" gem,因为 rc5 不需要.

如果您是从旧版 rc 升级,请确保更新您的 config/application.rb 文件,并运行以下命令:

heroku config:add PATH=vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin:bin

显然,这是在新应用中设置的,但现有应用尚未设置此 PATH.

I am having trouble deploying a rails 3.1 beta project to heroku. The problem happened at the database migration step. When I ran:

heroku rake db:migrate

I got error message:

> rake aborted! 

> Could not find a JavaScript runtime. See
> https://github.com/sstephenson/execjs
> for a list of available runtimes.

> /app/Rakefile:5 

> (See full trace by running task with --trace) 

> (in /app)

But I can successfully run the application locally, and I do have nodejs installed. Any idea why?

Here my gem list:

abstract (1.0.0)
actionmailer (3.1.0.beta1)
actionpack (3.1.0.beta1, 3.0.7)
activemodel (3.1.0.beta1, 3.0.7)
activerecord (3.1.0.beta1)
activeresource (3.1.0.beta1)
activesupport (3.1.0.beta1, 3.0.7)
ansi (1.2.5)
arel (2.1.0)
bcrypt-ruby (2.1.4)
builder (3.0.0, 2.1.2)
bundler (1.0.13)
coffee-script (2.2.0)
coffee-script-source (1.1.0)
configuration (1.2.0)
daemon_controller (0.2.6)
erubis (2.7.0, 2.6.6)
execjs (1.0.0, 0.3.3)
fastthread (1.0.7)
heroku (2.1.4)
hike (1.0.0)
i18n (0.6.0beta1, 0.5.0)
jquery-rails (1.0.1)
json (1.5.1)
json_pure (1.5.1)
launchy (0.4.0)
mail (2.3.0)
mime-types (1.16)
minitest (1.6.0)
multi_json (1.0.1)
mysql (2.8.1)
mysql2 (0.3.2)
oauth (0.4.4)
passenger (3.0.7)
polyglot (0.3.1)
rack (1.3.0.beta, 1.2.2)
rack-cache (1.0.1)
rack-mount (0.7.2, 0.6.14)
rack-ssl (1.3.2)
rack-test (0.6.0, 0.5.7)
rails (3.1.0.beta1)
railties (3.1.0.beta1)
rake (0.8.7)
rdoc (2.5.8)
rest-client (1.6.1)
rubygems-update (1.8.1)
sass (3.1.1)
simplegeo (0.5.1)
sprockets (2.0.0.beta.2)
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3)
term-ansicolor (1.0.5)
therubyracer-heroku (0.8.1.pre3)
thor (0.14.6)
tilt (1.3)
treetop (1.4.9)
turn (0.8.2)
tzinfo (0.3.27)
uglifier (0.5.1)

解决方案

You need a JavaScript engine for Rails 3.1 (heroku doesn’t have one), and it appears that the JavaScript engine that works with Heroku is the rubyracer for heroku.

Rails uses execjs to execute JavaScript and execjs supports 7 JavaScript engines. Node.js is one, and rubyracer is one.

Gerred Dillon had a similar problem and wrote about it. In the comment section a point was raised about making this a production only change, since you already have nodejs as your local JavaScript engine. So the relevant code is:

group :production do
  gem 'therubyracer-heroku', '0.8.1.pre3'
end

UPDATE: Heroku has a new stack, called Cedar, that they recommend for Rails 3.1.0. (Run heroku stack to see what stack your app is on.) Heroku also has a doc about upgrading to Rails 3.1.0 rc5. They recommend not using the ‘therubyracer-heroku’ gem anymore as it’s not necessary with rc5.

If you are upgrading from an older rc, make sure to update your config/application.rb file, and also run this command:

heroku config:add PATH=vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin:bin

Apparently, this is set in new apps, but existing apps have not set this PATH.

这篇关于将 Rails 3.1 项目部署到 Heroku 时出现问题:找不到 JavaScript 运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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