在Heroku上,rake assets:precompile无法工作

16

我的网站以前一直正常运行,Heroku也预编译了所有的资源。但是现在,似乎突然间,在部署时出现了rake aborted! stack level too deep错误。

从我的application.css文件中删除*= require_tree .这一行似乎可以解决stack level too deep的问题,但这样做会导致另一个错误:

Running: rake assets:precompile
(in /tmp/build_b8o2t4k8frce)
/usr/local/bin/ruby /tmp/build_b8o2t4k8frce/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
(in /tmp/build_b8o2t4k8frce)

我的所有图片链接都失效了(我在CSS文件中使用image-url())。可能的问题是什么,如何解决?

我正在使用cedar stack,这是我的Gemfile:

gem 'rails', '3.1.0'
gem 'rake', '0.8.7'
gem 'devise'

group :production do
  gem 'pg'
  gem 'thin'
end

group :assets do
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end

以下是Heroku所使用的版本:

Using rake (0.8.7)
Using rails (3.1.0)
Using sass (3.1.15)
Using sass-rails (3.1.6)

这是我的application.rb文件。
if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require *Rails.groups(:assets => %w(development test))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

module App
  class Application < Rails::Application

    # Enable the asset pipeline
    config.assets.enabled = true

    # Version of your assets, change this if you want to expire all your assets.
    config.assets.version = '1.0'
  end
end

这是我的production.rb文件:

# Full error reports are disabled and caching is turned on
config.consider_all_requests_local       = false
config.action_controller.perform_caching = true

# Enable Rails's static asset server (Apache or nginx will not need this)
config.serve_static_assets = true

# Set expire header of 30 days for static files
config.static_cache_control = "public, max-age=2592000"

# Allow JavaScript and CSS compression
config.assets.compress = true

# Compress JavaScript by removing whitespace, shortening variable names, ...
config.assets.js_compressor = :uglifier

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true

# Generate digests for assets URLs
config.assets.digest = true
3个回答

34

5
哇,就是这样!问题解决了!事实上,我是个新手,我以为这行代码gem 'sass-rails', "~> 3.1.0"意味着我的 gem 版本已被锁定,但显然这个波浪符号(或者叫它什么名字)允许 gem 被更新。也许就是这个原因,内部的 Heroku 改变了一些东西,突然间我的应用程序停止工作了。真的很奇怪,这让我白白浪费了一整天时间。对于任何可能会来到这里的人,解决方案是将那一行改为 gem 'sass-rails',"3.1.4" - Ashitaka
谢谢 - 大帮助 - 突然出现了同样的问题。今天我最不想看到的就是推送到Heroku失败。 - jpw

1

你不应该删除 application.css 中的 *= require tree .,因为它会加载所有的样式。只需要添加它,并配置你的 config/production.rb 文件如下:

config.assets.precompile = %w{application.js}

并运行RAILS_ENV=production rake assets:precompile

编辑 尝试使用此配置:

config.assets.digest  = true

是的,这应该可以使用require_tree,但如果我添加它,那么我会得到rake aborted!stack level too deep。我不知道这是怎么发生的。 - Ashitaka
抱歉,我忘记复制那一行代码了,我已经在使用摘要了。虽然我找到了一个解决方法,但我并不太喜欢它。 - Ashitaka

0

显然,Sass停止工作了,我已经失去了耐心,所以我决定不再使用它。而是这样做:

#theme.css.scss
background-image:image-url('image.png');

现在我只是使用一个erb文件:

#theme.css.erb
background-image:url(<%= asset_path 'image.png' %>);

我因为这个问题浪费了一整天的时间,但我不知道原因,因为昨天它还能正常工作。如果有人知道是什么原因导致的,并且知道如何再次使用sass,请留言告诉我。


我注意到在某些使用sass的环境中,如果我的语句中冒号和值之间没有空格,就会出现错误。因此,与其写类似于“background-image:image-url('image.png')”这样的代码,不如写成“background-image: image-url('image.png')”,注意在冒号后面加上空格。 - Tyrone Wilson

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