将 Rails 3.1 项目部署到 Heroku 时出现问题:找不到 JavaScript 运行时

发布于 2024-11-08 21:47:42 字数 1652 浏览 0 评论 0 原文

我在将 Rails 3.1 beta 项目部署到 Heroku 时遇到问题。问题发生在数据库迁移步骤。当我运行时:

heroku rake db:migrate

我收到错误消息:

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

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

这是我的宝石清单:

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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

滥情稳全场 2024-11-15 21:47:42

您需要一个用于 Rails 3.1 的 JavaScript 引擎(heroku 没有),并且与 Heroku 一起使用的 JavaScript 引擎似乎是 用于 Heroku 的 ruby​​racer

Rails 使用 execjs 来执行 JavaScript,execjs 支持 7 个 JavaScript 引擎。 Node.js 是其中之一,rubyracer 是其中之一。

Gerred Dillon 也有类似的问题并写了相关文章。在评论部分,有人提出了将其仅作为生产更改的观点,因为您已经将 NodeJS 作为本地 JavaScript 引擎。所以相关的代码是:

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

更新: Heroku 有一个新的堆栈,称为 Cedar,他们推荐 Rails 3.1.0。 (运行 heroku stack 查看您的应用程序所在的堆栈。)Heroku 还有一个 关于升级到 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。

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.

愛上了 2024-11-15 21:47:42

您不一定需要 JavaScript 运行时才能将 Rails 3.1 beta 部署到 heroku。

仅当您在部署时缩小 JavaScript(即通过 uglifier gem)或使用咖啡脚本时,才需要 JavaScript 运行时。

看起来 3.1 最终版本中不会存在此 javascript 运行时依赖项。

如果您不介意不缩小您的 JavaScript(并且如果您不使用 Coffee-Script),那么您可以在 Gemfile 中注释掉 coffee-script、uglifier 和 execjs gem,还可以在 生产.rb 中注释掉 config.assets.js_compressor ,然后就可以开始了。

You don't necessarily need a JavaScript runtime to deploy Rails 3.1 beta to heroku.

The JavaScript runtime is only required if you are minifying javascript on deployment (i.e., via the uglifier gem) or if you are using coffee-script.

It looks like this javascript runtime dependency will not be there for the 3.1 final release.

In case you don't mind not minifying your javascript (and also if you're not using coffee-script), then you can comment out the coffee-script, uglifier and execjs gems in the Gemfile and also comment out config.assets.js_compressor in your production.rb and you should be good to go.

绝影如岚 2024-11-15 21:47:42

截至本文发布之日,您仍然需要在 gemfile 中指定

gem 'therubyracer-heroku'、'0.8.1.pre3'

才能成功将 Rails 3.1 应用程序部署到 Heroku 的 Cedar 平台。

虽然可以将 Node 应用程序部署到 Cedar 平台,但在部署 Rails 应用程序时,Node 本身并不存在于 Cedar 堆栈上,因此您必须捆绑自己的 javascript 运行时。

目前。

我知道 Rails 方面的人们正在努力消除对 js 运行时的依赖,http://yehudakatz.com/2011/06/14/what-the-hell-is-happening-to-rails/
我确信 Heroku 也在研究使 Rails 3.1 部署正常工作的方法。

As of the date of this post you still need to specify

gem 'therubyracer-heroku', '0.8.1.pre3'

in your gemfile in order to successfully deploy a Rails 3.1 app to Heroku's Cedar platform.

While it is possible to deploy Node apps to the Cedar platform, Node itself is not present on the Cedar stack when deploying Rails apps, so you have to bundle your own javascript runtime.

For now.

I know the people on the Rails side of things are working to remove the dependency on having a js runtime, http://yehudakatz.com/2011/06/14/what-the-hell-is-happening-to-rails/
and I'm sure that Heroku is also looking into ways to make Rails 3.1 deployments just work.

如果没有 2024-11-15 21:47:42

就我而言,这是在成功上传到 Heroku 并访问页面后发生的。

ActionView::Template::Error (Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
2012-01-09T08:21:19+00:00 app[web.1]:   (in /app/app/assets/javascripts/page.js.coffee)):

使用“heroku config:add PATH blah”设置路径没有帮助。

“rake asset:precompile”刚刚解决了它。

希望它能帮助像我这样的人!

In my case, it happened after successful upload to Heroku and accessing the page.

ActionView::Template::Error (Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
2012-01-09T08:21:19+00:00 app[web.1]:   (in /app/app/assets/javascripts/page.js.coffee)):

Setting path using 'heroku config:add PATH blah' didn't help.

"rake assets:precompile" just solved it.

Hope it helps anyone like me!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文