ruby-on-rails - Rails 4 Heroku 部署错误 : Precompiling assets failed - cannot import/find boostrap file

标签 ruby-on-rails ruby twitter-bootstrap heroku sass

我的应用程序在本地运行;但是,当我尝试将其部署到 Heroku 时,出现以下错误:

remote:        Sass::SyntaxError: File to import not found or unreadable: bootstrap/dist/css/bootstrap.
remote:        (sass):18
.....
remote:        /tmp/build_c0c6ec9ea8e1ea183aca6e660993c246/vendor/bundle/ruby/2.2.0/gems/sprockets-rails-3.0.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
remote:        
Sass::SyntaxError: File to import not found or unreadable: bootstrap/dist/css/bootstrap.
.....
remote:        Tasks: TOP => assets:precompile
remote:        (See full trace by running task with --trace)
remote:  !
remote:  !     Precompiling assets failed.
remote:  !

以下是 application.scss 和 Gemfile 文件(按顺序排列):

application.scss:

 *= require_self
 *= require custom
 *= require template
 */
 @import "bootstrap-sprockets";
 @import "bootstrap";

Gemfile:

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
# Specify Rake version
gem 'rake'
# Use postgresql as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use bootstrap sass?
gem 'bootstrap-sass', '>= 3.3.6'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# For user authentication and registration
gem 'devise'

# Font Awesome and simple form
gem 'simple_form'

# For static pages
gem 'high_voltage'

gem 'paperclip', '~> 3.5.3' # github: 'thoughtbot/paperclip

gem 'closure_tree'

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

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

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  gem 'rspec-rails'
  gem 'capybara'
  gem 'launchy'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

我的供应商/ Assets 文件夹如下所示: enter image description here

更新 - 对我的 application.scss 所做的更改不会被推送到 Heroku。我之所以这么认为,是因为即使我删除了所有的需求和导入,Heroku 预编译似乎仍然在寻找(而不是找到) Bootstrap !

感谢任何帮助 - 如果我错过了什么,请告诉我!

提前致谢。

最佳答案

  1. 您需要在 application.scss 中导入如下所示的 Bootstrap 文件:

    @import "bootstrap-sprockets";
    @import "bootstrap";
    
  2. 然后,从 sass 文件中删除所有 *= require_self*= require_tree . 语句。相反,使用 @import 导入 Sass 文件。

    请勿在 Sass 中使用 *= require ,否则您的其他样式表将无法访问 Bootstrap mixins 或变量。请参阅sass-rails gem documentation了解更多相关信息。

  3. 运行$ rake assets:precompile

  4. 运行$ git add --all

  5. 运行$ git commit -m '切换到导入语法'

  6. 运行$ git push heroku master

关于ruby-on-rails - Rails 4 Heroku 部署错误 : Precompiling assets failed - cannot import/find boostrap file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35276922/

相关文章:

ruby-on-rails - 为生产 Rails 应用程序设置管理员用户

ruby-on-rails - ActionMailer 错误的参数数量错误

mysql - Rails update_attribute 没有命中 mysql 数据库

php - 将 Bootstrap 模式部分 View 动态插入 View 中

html - 用背景颜色填充 Bootstrap 中的图像

ruby-on-rails - 无需测试的Ruby On Rails项目

ruby-on-rails - rails +装置: Trying to delete user account

ruby-on-rails - rake 数据库 :test:prepare erroring out due to PG error

ruby - 使用 RMagick 合成处理过的图像

css - 如何使用 Bootstrap RTL 获得所需的按钮 View ?