将 Rails 3.1 项目部署到 Heroku 时出现问题:找不到 JavaScript 运行时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6075961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Problem deploying Rails 3.1 project to Heroku: Could not find a JavaScript runtime
提问by WYi
I am having trouble deploying a rails 3.1 beta project to heroku. The problem happened at the database migration step. When I ran:
我在将 rails 3.1 beta 项目部署到 heroku 时遇到问题。问题发生在数据库迁移步骤。当我跑:
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?
但是我可以在本地成功运行该应用程序,并且我确实安装了 nodejs。知道为什么吗?
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)
回答by c3rin
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 3.1 的 JavaScript 引擎(heroku 没有),而且与 Heroku 一起使用的 JavaScript 引擎似乎是heroku的rubyracer。
Rails uses execjs to execute JavaScript and execjs supports 7 JavaScript engines. Node.js is one, and rubyracer is one.
Rails 使用 execjs 来执行 JavaScript,execjs 支持 7 个 JavaScript 引擎。Node.js 是其中之一,而 rubyracer 是其中之一。
Gerred Dillonhad 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:
Gerred Dillon也有类似的问题,并写了一篇文章。在评论部分中提出了一个关于使其成为仅生产更改的观点,因为您已经将 nodejs 作为您的本地 JavaScript 引擎。所以相关的代码是:
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 docabout upgrading to Rails 3.1.0 rc5. They recommend notusing the ‘therubyracer-heroku' gem anymore as it's not necessary with rc5.
更新:Heroku 有一个名为Cedar的新堆栈,他们推荐用于 Rails 3.1.0。(运行heroku stack
看什么堆栈您的应用程序打开)Heroku上也有一个文档有关升级到Rails 3.1.0 RC5。他们建议不要再使用 'therubyracer-heroku' gem,因为 rc5 不需要它。
If you are upgrading from an older rc, make sure to update your config/application.rb file, and also run this command:
如果您是从较旧的 rc 升级,请确保更新您的 config/application.rb 文件,并运行以下命令:
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.
显然,这是在新应用程序中设置的,但现有应用程序尚未设置此 PATH。
回答by caike
You don't necessarily need a JavaScript runtime to deploy Rails 3.1 beta to heroku.
您不一定需要 JavaScript 运行时才能将 Rails 3.1 beta 部署到 heroku。
The JavaScript runtime is only required if you are minifying javascript on deployment (i.e., via the uglifiergem) or if you are using coffee-script.
仅当您在部署时缩小 javascript(即,通过uglifiergem)或使用咖啡脚本时,才需要 JavaScript 运行时。
It looks like this javascript runtime dependency will not be there for the 3.1 final release.
看起来这个 javascript 运行时依赖项不会出现在 3.1 最终版本中。
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 execjsgems in the Gemfile and also comment out config.assets.js_compressorin your production.rband you should be good to go.
如果您不介意不缩小您的 javascript(并且如果您不使用 coffee-script),那么您可以在 Gemfile 中注释掉coffee-script、uglifier 和 execjsgems,并注释掉config.assets。 js_compressor在您的production.rb 中,您应该很高兴。
回答by Deathbob
As of the date of this post you still need to specify
截至本文发布之日,您仍然需要指定
gem 'therubyracer-heroku', '0.8.1.pre3'
宝石“therubyracer-heroku”,“0.8.1.pre3”
in your gemfile in order to successfully deploy a Rails 3.1 app to Heroku's Cedar platform.
在您的 gemfile 中,以便将 Rails 3.1 应用程序成功部署到 Heroku 的 Cedar 平台。
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.
虽然可以将 Node 应用程序部署到 Cedar 平台,但在部署 Rails 应用程序时,Node 本身并不存在于 Cedar 堆栈中,因此您必须捆绑自己的 javascript 运行时。
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.
我知道 Rails 方面的人正在努力消除对 js 运行时的依赖,http://yehudakatz.com/2011/06/14/what-the-hell-is-happening-to-rails/而且我确信 Heroku 也在寻找使 Rails 3.1 部署正常工作的方法。
回答by nextofsearch
In my case, it happened after successful upload to Heroku and accessing the page.
就我而言,它是在成功上传到 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)):
Setting path using 'heroku config:add PATH blah' didn't help.
使用 'heroku config:add PATH blah' 设置路径没有帮助。
"rake assets:precompile" just solved it.
“耙资产:预编译”刚刚解决了它。
Hope it helps anyone like me!
希望它能帮助像我一样的人!