Gem bootstrap sass gem 的 precompile 真是无解...

jossjoss54 · 2014年10月17日 · 最后由 beiersi 回复于 2014年10月19日 · 5603 次阅读

当我用这指令时

RAILS_ENV="production" bundle exec rake assets:precompile RAILS_GROUPS=assets

就会出现以下错误:

I, [2014-10-17T19:27:35.964117 #1687]  INFO -- : Writing /home/ubuntu/*/*/tmp/build-141354439930527/public/assets/bootstrap-dfdddb4ad2b1dff678f8c9039c7356ce.css
     rake aborted!
     Sass::SyntaxError: Undefined variable: "$alert-padding".

但是运行

RAILS_ENV="production" bundle exec rake assets:precompile 

就没问题! 这真是诡异,我去翻 3.1.1 的文件 http://www.rubydoc.info/gems/bootstrap-sass/3.1.1.1/frames 也没看到异样,都照他的设定了 我的 ruby 2.0.0 及 rails 4.0.2 以下是我的设定档 /javascripts/application.js

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require ckeditor/override
//= require ckeditor/init
//= require_tree ./common
//= require s3_direct_upload
//= require analytics

/stylesheets/application.css

*
 *= require_self
 *= require s3_direct_upload_progress_bars
 *= require bootstrap
 *= require_tree .
 */

gemfile

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.0.2)
      actionpack (= 4.0.2)
      mail (~> 2.5.4)
    actionpack (4.0.2)
      activesupport (= 4.0.2)
      builder (~> 3.1.0)
      erubis (~> 2.7.0)
      rack (~> 1.5.2)
      rack-test (~> 0.6.2)
    activemodel (4.0.2)
      activesupport (= 4.0.2)
      builder (~> 3.1.0)
    activerecord (4.0.2)
      activemodel (= 4.0.2)
      activerecord-deprecated_finders (~> 1.0.2)
      activesupport (= 4.0.2)
      arel (~> 4.0.0)
    activerecord-deprecated_finders (1.0.3)
    activerecord-session_store (0.1.0)
      actionpack (>= 4.0.0, < 5)
      activerecord (>= 4.0.0, < 5)
      railties (>= 4.0.0, < 5)
    activesupport (4.0.2)
      i18n (~> 0.6, >= 0.6.4)
      minitest (~> 4.2)
      multi_json (~> 1.3)
      thread_safe (~> 0.1)
      tzinfo (~> 0.3.37)
    annotate (2.5.0)
      rake
    arel (4.0.2)
    autoprefixer-rails (3.1.2.20141016)
      execjs
    aws-sdk (1.56.0)
      aws-sdk-v1 (= 1.56.0)
    aws-sdk-v1 (1.56.0)
      json (~> 1.4)
      nokogiri (>= 1.4.4)
    bcrypt-ruby (3.1.2)
    better_errors (2.0.0)
      coderay (>= 1.0.0)
      erubis (>= 2.6.6)
      rack (>= 0.9.0)
    binding_of_caller (0.7.2)
      debug_inspector (>= 0.0.1)
    bootstrap-sass (3.1.1.1)
      sass (~> 3.2)
    builder (3.1.4)
    callsite (0.0.11)
    ckeditor (4.0.11)
      mime-types
      orm_adapter (~> 0.5.0)
    climate_control (0.0.3)
      activesupport (>= 3.0)
    cocaine (0.5.4)
      climate_control (>= 0.0.3, < 1.0)
    coderay (1.1.0)
    coffee-rails (4.0.1)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0, < 5.0)
    coffee-script (2.3.0)
      coffee-script-source
      execjs
    coffee-script-source (1.8.0)
    debug_inspector (0.0.2)
    erubis (2.7.0)
    execjs (2.2.2)
    hike (1.2.3)
    html5shiv-js-rails (3.7.2.1)
      railties (~> 4.0, < 5.0)
    i18n (0.6.11)
    jbuilder (1.5.3)
      activesupport (>= 3.0.0)
      multi_json (>= 1.2.0)
    jquery-fileupload-rails (0.4.1)
      actionpack (>= 3.1)
      railties (>= 3.1)
    jquery-rails (3.1.2)
      railties (>= 3.0, < 5.0)
      thor (>= 0.14, < 2.0)
    json (1.8.1)
    kaminari (0.15.1)
      actionpack (>= 3.0.0)
      activesupport (>= 3.0.0)
    mail (2.5.4)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    meta_request (0.3.4)
      callsite (~> 0.0, >= 0.0.11)
      rack-contrib (~> 1.1)
      railties (>= 3.0.0, < 5.0.0)
    mime-types (1.25.1)
    mina (0.3.0)
      open4
      rake
    mini_portile (0.6.0)
    minitest (4.7.5)
    multi_json (1.10.1)
    mysql2 (0.3.16)
    newrelic_rpm (3.9.5.251)
    nokogiri (1.6.2.1)
      mini_portile (= 0.6.0)
    open4 (1.3.4)
    orm_adapter (0.5.0)
    paperclip (4.1.1)
      activemodel (>= 3.0.0)
      activesupport (>= 3.0.0)
      cocaine (~> 0.5.3)
      mime-types
    polyglot (0.3.5)
    pr_geohash (1.0.0)
    protected_attributes (1.0.7)
      activemodel (>= 4.0.1, < 5.0)
    rack (1.5.2)
    rack-contrib (1.1.0)
      rack (>= 0.9.1)
    rack-test (0.6.2)
      rack (>= 1.0)
    rails (4.0.2)
      actionmailer (= 4.0.2)
      actionpack (= 4.0.2)
      activerecord (= 4.0.2)
      activesupport (= 4.0.2)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.0.2)
      sprockets-rails (~> 2.0.0)
    railties (4.0.2)
      actionpack (= 4.0.2)
      activesupport (= 4.0.2)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (10.3.2)
    rdoc (4.1.2)
      json (~> 1.4)
    rsolr (1.0.10)
      builder (>= 2.1.2)
    s3_direct_upload (0.1.7)
      coffee-rails (>= 3.1)
      jquery-fileupload-rails (~> 0.4.1)
      rails (>= 3.1)
      sass-rails (>= 3.1)
    sass (3.2.19)
    sass-rails (4.0.3)
      railties (>= 4.0.0, < 5.0)
      sass (~> 3.2.0)
      sprockets (~> 2.8, <= 2.11.0)
      sprockets-rails (~> 2.0)
    sdoc (0.4.1)
      json (~> 1.7, >= 1.7.7)
      rdoc (~> 4.0)
    simple_captcha2 (0.2.2)
      rails (>= 3.1, < 4.1)
    sprockets (2.11.0)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sprockets-rails (2.0.1)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      sprockets (~> 2.8)
    sqlite3 (1.3.9)
    sunspot (2.1.1)
      pr_geohash (~> 1.0)
      rsolr (~> 1.0.7)
    sunspot_rails (2.1.1)
      nokogiri
      rails (>= 3)
      sunspot (= 2.1.1)
    sunspot_solr (2.1.1)
    thor (0.19.1)
    thread_safe (0.3.4)
    tilt (1.4.1)
    treetop (1.4.15)
      polyglot
      polyglot (>= 0.3.1)
    turbolinks (2.4.0)
      coffee-rails
    tzinfo (0.3.41)
    uglifier (2.5.3)
      execjs (>= 0.3.0)
      json (>= 1.8.0)

PLATFORMS
  ruby

DEPENDENCIES
  activerecord-session_store
  annotate (= 2.5.0)
  autoprefixer-rails (~> 3.1.2.20141016)
  aws-sdk
  bcrypt-ruby (= 3.1.2)
  better_errors
  binding_of_caller
  bootstrap-sass (~> 3.1.1)
  ckeditor (= 4.0.11)
  coffee-rails (~> 4.0.0)
  html5shiv-js-rails
  jbuilder (~> 1.2)
  jquery-rails
  kaminari (= 0.15.1)
  meta_request
  mina (~> 0.3.0)
  mysql2
  newrelic_rpm
  nokogiri (~> 1.6.2.1)
  paperclip (= 4.1.1)
  protected_attributes (= 1.0.7)
  rails (= 4.0.2)
  s3_direct_upload
  sass-rails (~> 4.0.0)
  sdoc
  simple_captcha2
  sqlite3
  sunspot_rails (= 2.1.1)
  sunspot_solr (= 2.1.1)
  turbolinks
  uglifier (>= 1.3.0)

前几天我也遇到了,后来发现是以前在 vender 文件下下引入了非 gem 版的 bootstrap 文件 (忘记删除了),删除之后就没再报错了

用 CSS 的文件都简单啊,这不是折腾么

我用 mina 跟 capistrano 都有 group,真是奇怪

我如果用官方的 css 和 js 文件,precompile 就会各种报错,用 gem 装就木问题

https://github.com/twbs/bootstrap-sass/ readme 里有这样一段话: Do not use //= require in Sass or your other stylesheets will not be able to access the Bootstrap mixins or variables.

用法应该是: app/assets//stylesheets/application.scss

/**
 *= require_self
 */

@import "bootstrap-sprockets";
@import "bootstrap";
需要 登录 后方可回复, 如果你还没有账号请 注册新账号