web-dev-qa-db-ja.com

railsブートストラップsassアセットのコンパイルエラー-未定義の変数アラートパディング

すべての道路がbootstrap-sassを指しています

紹介チェーン:

これは、bootstrap-Rails gemの問題として報告されています: https://github.com/anjlab/bootstrap-Rails/issues/91

正しくインストールしたと思います

宝石

_gem 'sass-Rails', '>= 3.2' # sass-Rails needs to be higher than 3.2
gem 'bootstrap-sass', '~> 3.1.1'
_

インストール(アセットグループの外部および内部で試行)、application.css.scssには

_@import "bootstrap";
_

のみ。

エラーが出ます

_bundle exec rake assets:precompile_を試行すると、次のエラーが発生します。

_rake aborted!
Undefined variable: "$alert-padding".
  (in /home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/bootstrap-sass-3.1.1.0/vendor/assets/stylesheets/bootstrap/_alerts.scss)
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/bootstrap-sass-3.1.1.0/vendor/assets/stylesheets/bootstrap/_alerts.scss:10
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/script/variable.rb:49:in `_perform'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/script/node.rb:40:in `perform'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:298:in `visit_prop'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:37:in `visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:100:in `visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:53:in `map'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:53:in `visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:109:in `block in visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:121:in `with_environment'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:108:in `visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:37:in `block in visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:320:in `visit_rule'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:37:in `visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:100:in `visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:53:in `block in visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:53:in `map'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:53:in `visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:109:in `block in visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:121:in `with_environment'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:108:in `visit_children'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:37:in `block in visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:128:in `visit_root'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/base.rb:37:in `visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:100:in `visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/visitors/perform.rb:7:in `visit'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/tree/root_node.rb:20:in `render'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/engine.rb:315:in `_render'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-3.2.7/lib/sass/engine.rb:262:in `render'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sass-Rails-3.2.6/lib/sass/Rails/template_handlers.rb:106:in `evaluate'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/tilt-1.3.7/lib/tilt/template.rb:77:in `render'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:193:in `block in evaluate'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `each'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `evaluate'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/processed_asset.rb:16:in `initialize'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/base.rb:18:in `new'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/base.rb:18:in `block in build_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:270:in `circular_call_protection'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/base.rb:14:in `build_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/index.rb:14:in `find_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/bundled_asset.rb:12:in `initialize'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/base.rb:22:in `new'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/base.rb:22:in `build_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/index.rb:14:in `find_asset'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/static_compiler.rb:41:in `block in compile'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:219:in `block in each_logical_path'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:206:in `block (2 levels) in each_file'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each_entry'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:204:in `block in each_file'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each_file'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:217:in `each_logical_path'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/sprockets_overrides/static_compiler.rb:29:in `compile'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/tasks/assets.rake:108:in `internal_precompile'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/turbo-sprockets-Rails3-0.3.11/lib/turbo-sprockets/tasks/assets.rake:115:in `block (3 levels) in <top (required)>'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in `<top (required)>'
/home/joe/.rbenv/versions/1.9.3-p448/bin/rake:23:in `load'
/home/joe/.rbenv/versions/1.9.3-p448/bin/rake:23:in `<main>'
_

_/home/joe/.rbenv/versions/1.9.3-p448/lib/Ruby/gems/1.9.1/gems/bootstrap-sass-3.1.1.0/vendor/assets/stylesheets/bootstrap.scss_が実際にその下の_variables.scssファイルを_bootsrap/_ディレクトリに最初にインポートすることを確認しました(_alerts.scssの前など)... _variables.scssで$を定義していますalert_padding。

私は明らかな何かを見逃していると思います

_environments/production.rb_ファイルで、アセットに関するすべてをコメントアウトし、マニュアル_config.assets.initialize_on_precompile = true_に従って_https://github.com/twbs/bootstrap-sass_だけを試してみました

これまでの研究

特定された問題

宝石のコンテンツを私のアセットディレクトリにコピーしました。これは基本的にjlong​​のbootstrapが行ったことです。

それは_application.css.scss_を見ていない...私がそこに置いたものを無視し、代わりにフォルダを調べてそれらのファイルをロードすることを選択した。そのため、alerts.scssが最初に表示されます。 _variables.scssの名前を_aavariables.scssに変更してみたが、役に立たなかった

23
xxjjnn

私の特定の問題は、application.rb...に隠れているコードであることが判明しました...

どうやって見つけたの

私はputs config.assets.precompile.inspectconfig/environments/production.rbに追加し、それが出力する正規表現に驚嘆しました。次に、コードベースで「config.assets.precompile」を検索したところ、application.rbに次のように表示されました。

config.assets.precompile << /(^[^_\/]|\/[^_])[^\/]*$/
...
config.assets.precompile += ["*.js", "*.css", "jquery-migrate-Rails.js"]

これが問題の原因でした。 (私はそれらの正規表現をトリプルチェックし、それらが_alerts.scssを取得するべきではないので少し戸惑っています...しかし、それを理解し、それらの行を削除することで修正されるという事実に焦点を当てます)

多分これは誰かを助けるでしょう...

17
xxjjnn

理由はわかりませんが、私にとってはassets.rbこの行

Rails.application.config.assets.precompile += [/^[-_a-zA-Z0-9]*\..*/]

最初はSass :: SyntaxError:Undefined variable: "$ alert-padding"。problemがこの行にありました

Rails.application.config.assets.precompile += [/.*\.css/] 

しかし、それを最初のものに変更した後、問題は解決され、すべてが本番環境で機能しました。

2
Seybo Glaux

アセットのグロビングとプリコンパイルに問題があります。 https://github.com/twbs/bootstrap-sass/issues/86

Jsおよびcssアセットをプリコンパイルする必要がある場合:

Rails.application.config.assets.precompile += [proc { |filename, path| path =~ /(app|lib|vendor)\/assets/ && ['.js', '.css'].include?(File.extname(filename)) }]

基本的に、このプロシージャは、アセットのアプリライブラリとベンダーフォルダを検索します。

また、このコードを思いつくために Rails Guide のセクションを使用しました

1
DRSisco

私はRails 4.で同じ問題に直面していました。gemsを上書きする解決策を見つけました。そのため、bootstrap gem bootstrap-sass-X.X.X.Xvendorsフォルダー内の変更より、gemパスのGemfile内の変更

  gem 'bootstrap-sass', '3.3.1.0', :path => 'vendor/bootstrap-sass-X.X.X.X'
  than write these 2 line
    @import "bootstrap/variables";
    @import "bootstrap/mixins";
  at top of each of file which are inside the bootstrap folder
  (vendor/bootstrap-sass-X.X.X.X/assets/stylesheets/bootstrap)

  //like for _alerts.scss

  // Alerts
  // --------------------------------------------------
    @import "bootstrap/variables";
    @import "bootstrap/mixins";

  // Base styles
  // -------------------------
1
Vinay Shankar