本文介绍了Heroku预编译资产失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新后,我的应用突然无法运行.不知道出了什么问题.基本上,当我推送到heroku时,会出现以下错误:

My app is suddenly not working after an update. Not sure what's going wrong. Basically, when I push to heroku, I get these errors:

Precompiling assets failed, enabling runtime asset compilation
Injecting rails31_enable_runtime_asset_compilation

往上一点:

   rake aborted!
   Unexpected token: operator (>) (line: 19073, col: 9, pos: 605247)
   Error
   at new JS_Parse_Error (/tmp/execjs20121211-811-1z5vum.js:1720:22)
   at js_error (/tmp/execjs20121211-811-1z5vum.js:1728:15)
   at croak (/tmp/execjs20121211-811-1z5vum.js:2189:17)
   at token_error (/tmp/execjs20121211-811-1z5vum.js:2196:17)
   at unexpected (/tmp/execjs20121211-811-1z5vum.js:2202:17)
   at /tmp/execjs20121211-811-1z5vum.js:2580:17
   at maybe_unary (/tmp/execjs20121211-811-1z5vum.js:2665:27)
   at expr_op (/tmp/execjs20121211-811-1z5vum.js:2685:45)
   at expr_ops (/tmp/execjs20121211-811-1z5vum.js:2692:24)
   at maybe_conditional (/tmp/execjs20121211-811-1z5vum.js:2696:28)

当我实际加载网站时(很抱歉,出了点问题"),然后查看heroku日志,我得到了:

When I actually load up the site ("We're sorry, but something went wrong"), and look at the heroku logs, I get this:

Load path: /app
2012-12-11T23:18:13+00:00 app[web.1]:     8:     <%= stylesheet_link_tag "application", :media => "all" %>
2012-12-11T23:18:13+00:00 app[web.1]:   (in /app/app/assets/stylesheets/custom.css.scss)):
2012-12-11T23:18:13+00:00 app[web.1]:     6:     <link href='http://fonts.googleapis.com/css?family=Kreon' rel='stylesheet' type='text/css'>
2012-12-11T23:18:13+00:00 app[web.1]: ActionView::Template::Error (File to import not found or unreadable: bootstrap.
2012-12-11T23:18:13+00:00 app[web.1]:     5:     <title><%= full_title(yield(:title)) %></title>
2012-12-11T23:18:13+00:00 app[web.1]:     7:     <%= favicon_link_tag 'favicon.ico' %>
2012-12-11T23:18:13+00:00 app[web.1]:     10:     <%= csrf_meta_tags %>
2012-12-11T23:18:13+00:00 app[web.1]:   app/assets/stylesheets/custom.css.scss:1
2012-12-11T23:18:13+00:00 app[web.1]:     11:     <meta name="google-site-verification" content="idIPkgRBikSL9PCS4rVkkZfRjxYbPxNbyF6tVymBWbc" />
2012-12-11T23:18:13+00:00 app[web.1]:
2012-12-11T23:18:13+00:00 app[web.1]:

(Kreon是我不久前添加的另一种字体,效果很好.custom.css.scss是我的主要css文件,第一行是我以未更改且已正常运行的方式导入引导程序的位置永远).

(Kreon is an additional font I added a while back that's been working fine. custom.css.scss is my main css file, and the first line is where I import bootstrap in a way that hasn't changed and has worked forever).

我搜索了如何处理找不到未导入或不可读的文件:引导程序"错误,并进入此讨论,并查看了相关的heroku故障排除页面,但是在我的production.rb文件中将assets.compile更改为true会导致上面的heroku push错误,并且故障排除页面似乎与我的特定问题没有太大关系.不太确定这里发生了什么,因此我将在下面放置一堆可能相关的代码.

I searched for how to deal with the "File to import not found or unreadable: bootstrap" error, and landed on this discussion and checked out the relevant heroku troubleshoot page, but changing assets.compile to true in my production.rb file led to the heroku push errors above, and the troubleshoot page didn't seem to have much relevant to my specific problem. Not really sure what's going on here, so I'm just going to put a bunch of possibly relevant code below.

宝石文件

source 'https://rubygems.org'

gem 'rails', '3.2.8'
gem 'googlecharts', :require => "gchart"
gem 'unicorn'
gem 'newrelic_rpm'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :production do
    gem 'pg'
end

group :development do
    gem 'sqlite3'
    gem 'rspec-rails', '2.11.0'
  gem 'guard-rspec', '1.2.1'
end

group :test do
    gem 'capybara', '1.1.2'
  gem 'rb-fsevent', '0.9.1'
  gem 'growl', '1.0.3'
  gem 'guard-spork', '1.2.0'
  gem 'spork', '0.9.2'
  gem 'factory_girl_rails', '4.1.0'
end

gem 'annotate', '2.5.0'
gem 'faker', '1.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'bootstrap-sass', '2.0.4'
  gem 'bcrypt-ruby', '3.0.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'
gem 'roadie'
gem 'stripe', :git => 'https://github.com/stripe/stripe-ruby'
gem 'delayed_job_active_record'
gem 'daemons'
gem 'foreman'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

production.rb

production.rb

MyApp::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # Code is not reloaded between requests
  config.cache_classes = true

  # Force all access to the app over SSL, use Strict-Transport-Security,
  # and use secure cookies.
  config.force_ssl = true

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

  # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = false

  # Compress JavaScripts and CSS
  config.assets.compress = true

  # 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

  # Defaults to nil and saved in location specified by config.assets.prefix
  # config.assets.manifest = YOUR_PATH

  # Specifies the header that your server uses for sending files
  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # See everything in the log (default is :info)
  # config.log_level = :debug

  # Prepend all log lines with the following tags
  # config.log_tags = [ :subdomain, :uuid ]

  # Use a different logger for distributed setups
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

  # Use a different cache store in production
  # config.cache_store = :mem_cache_store

  # Enable serving of images, stylesheets, and JavaScripts from an asset server
  # config.action_controller.asset_host = "http://assets.example.com"

  # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
  # config.assets.precompile += %w( search.js )

  # Disable delivery errors, bad email addresses will be ignored
  # config.action_mailer.raise_delivery_errors = false

  # Enable threaded mode
  # config.threadsafe!

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation can not be found)
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners
  config.active_support.deprecation = :notify

  # Log the query plan for queries taking more than this (works
  # with SQLite, MySQL, and PostgreSQL)
  # config.active_record.auto_explain_threshold_in_seconds = 0.5
end

真正让我发狂的那行是我的heroku推送日志中的这一行:

The line that's really throwing me is this one in my heroku push log:

Unexpected token: operator (>) (line: 19073, col: 9, pos: 605247)

问题是,我不知道要为这个麻烦的>"查找哪个文件.有什么想法如何读取该行/列/位置的命名法以找到实际的违规代码段?

The issue, is I have no idea what file to look in for this troublesome ">". Any ideas how to read that line/col/pos nomenclature to find the actual offending code snippet?

谢谢.

推荐答案

使用app/assets/stylesheets/custom.css.scss的第1行输入START,然后查找错误的>.还要确保确保application.scss是您所期望的.

STart with line 1 of app/assets/stylesheets/custom.css.scss and look for an errant >.Also look to make sure that application.scss is what you expect.

也可以将custom.css.scss重命名为just custom.scss Heck,这可以做到.

Also just rename custom.css.scss to justcustom.scss Heck, that may do it.

这篇关于Heroku预编译资产失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 17:47