Ruby-on-rails Sass::SyntaxError: 要导入的文件未找到或无法读取:bootstrap-sprockets

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26135126/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:56:35  来源:igfitidea点击:

Sass::SyntaxError: File to import not found or unreadable: bootstrap-sprockets

ruby-on-railstwitter-bootstrap

提问by complete_morons

I am suddenly getting this error in development and in production on deployment.

我突然在开发和生产部署中遇到此错误。

custom.css.scss

自定义.css.scss

@import "bootstrap-sprockets";
@import "bootstrap";

error (in production)

错误(生产中)

rake aborted!
Sass::SyntaxError: File to import not found or unreadable: bootstrap-sprockets.
Load paths:
/srv/www/myapp/releases/20141001060418/app/assets/images
/srv/www/myapp/releases/20141001060418/app/assets/javascripts
/srv/www/myapp/releases/20141001060418/app/assets/stylesheets
/srv/www/myapp/releases/20141001060418/vendor/assets/javascripts
/srv/www/myapp/releases/20141001060418/vendor/assets/stylesheets

回答by Sergiu

After making changes to Gemfile, do not forget to restart the server with rails s

更改 Gemfile 后,不要忘记重新启动服务器 rails s

Restarting the rails server worked like a charm! :D

重新启动 rails 服务器就像一个魅力!:D

回答by flexus

I solved this issue by upgrading bootstrap-sass

我通过升级 bootstrap-sass 解决了这个问题

gem 'bootstrap-sass', '3.2.0.2'

回答by Azlan Jamal

Please restart you rails server after every changes in Gemfile

每次更改 Gemfile 后,请重新启动 Rails 服务器

rails server

回答by Mark Swardstrom

Make sure you don't have

确保你没有

gem 'bootstrap'  # Remove this line
gem 'bootstrap-sass'

It should just be

它应该只是

gem 'bootstrap-sass'

回答by Vitalie Suba

I solved it in following steps:

我通过以下步骤解决了它:

  1. List item
  2. copying the "bootstrap.css" in my "app/assets/stylesheets/ (it was missing)
  3. gem install autoprefixer-rails (also modify Gemfile)
  4. gem install sprockets (also modify Gemfile)
  5. bundle install
  6. RESTART server (not just refreshing page)
  1. 项目清单
  2. 在我的“app/assets/stylesheets/”中复制“bootstrap.css”(它丢失了)
  3. gem install autoprefixer-rails(同时修改Gemfile)
  4. gem 安装链轮(也修改 Gemfile)
  5. 捆绑安装
  6. 重启服务器(不仅仅是刷新页面)

回答by Adrian Onu

This is how I solved the issue.

这就是我解决问题的方法。

Go to Bootstrap for Sass Github pageand follow the instructions:

转到Bootstrap for Sass Github 页面并按照说明操作:

  1. Add the following to the Gemfile

    gem 'bootstrap-sass', '~> 3.3.6' gem 'sass-rails', '>= 3.2'

  2. Run the command bundle install

  3. Start/restart the server

    rails s

  1. 将以下内容添加到 Gemfile

    gem 'bootstrap-sass', '~> 3.3.6' gem 'sass-rails', '>= 3.2'

  2. 运行命令 bundle install

  3. 启动/重启服务器

    导轨

Also, make sure the file has .scss extension (or .sass for Sass syntax). If you have just generated a new Rails app, it may come with a .css file instead. If this file exists, it will be served instead of Sass, so rename it. Then, remove all the *= require_self and *= require_tree . statements from the sass file. Instead, use @import to import Sass files.

此外,请确保文件具有 .scss 扩展名(或 .sass 用于 Sass 语法)。如果您刚刚生成了一个新的 Rails 应用程序,它可能会附带一个 .css 文件。如果此文件存在,它将代替 Sass 提供服务,因此重命名它。然后,删除所有 *= require_self 和 *= require_tree 。sass 文件中的语句。相反,使用 @import 导入 Sass 文件。

回答by Deep Mistry

I have observed the same behaviour. In my case i have removed the version of the gem 'bootstap-sass' and it worked. There might be compatibility issue with the gem version which was causing the problem.

我观察到了同样的行为。就我而言,我已经删除了 gem 'bootstap-sass' 的版本并且它起作用了。导致问题的 gem 版本可能存在兼容性问题。

Gem file

宝石文件

gem 'bootstrap-sass'

After making changes in the gem file perform following commands:

在 gem 文件中进行更改后,执行以下命令:

bundle install

If the server is already running then stop it by "CTRL+C" and start the server again

如果服务器已经在运行,那么通过“ CTRL+C”停止它并再次启动服务器

rails s

回答by Godwin

In your Gemfile you need to add the bootstrap-sass gem, and ensure that the sass-rails gem is present - it is added to new Rails applications by default.

在您的 Gemfile 中,您需要添加 bootstrap-sass gem,并确保 sass-rails gem 存在 - 默认情况下它会添加到新的 Rails 应用程序中。

gem 'bootstrap-sass', '3.3.7'
gem 'sass-rails', '5.0.6'
gem 'rails', '5.0.0'

bundle install and restart your server to make the files available through the pipeline. Import Bootstrap styles in app/assets/stylesheets/application.scss:

bundle install 并重新启动您的服务器以使文件通过管道可用。在app/assets/stylesheets/application.scss 中导入 Bootstrap 样式

// "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
@import "bootstrap-sprockets";
@import "bootstrap";

bootstrap-sprockets must be imported before bootstrap for the icon fonts to work. Make sure the file has .scss extension (or .sass for Sass syntax). If you have just generated a new Rails app, it may come with a .css file instead. If this file exists, it will be served instead of Sass, so rename it:

bootstrap-sprockets 必须在 bootstrap 之前导入,图标字体才能工作。确保文件具有 .scss 扩展名(或 .sass 用于 Sass 语法)。如果您刚刚生成了一个新的 Rails 应用程序,它可能会附带一个 .css 文件。如果此文件存在,它将代替 Sass 提供服务,因此将其重命名:

$ mv app/assets/stylesheets/application.css TO:app/assets/stylesheets/application.scss

$ mv app/assets/stylesheets/application.css到:app/assets/stylesheets/application.scss

Then, remove all the *= require_selfand *= require_tree .statements from the sass file. Instead, use @importto import Sass files. e.g

然后,从 sass 文件中删除所有*= require_self*= require_tree .语句。相反,用于@import导入 Sass 文件。 例如

*= require_tree .
*= require_self

To:

到:

@import require_tree .
@import require_self

Do not use *= requirein Sass or your other stylesheets will not be able to access the Bootstrap mixins or variables. Bootstrap JavaScript depends on jQuery. If you're using Rails 5.1+, add the jquery-rails gem to your Gemfile:

不要*= require在 Sass 中使用,否则您的其他样式表将无法访问 Bootstrap 混合或变量。Bootstrap JavaScript 依赖于 jQuery。如果您正在使用Rails 5.1+,请将 jquery-rails gem 添加到您的 Gemfile:

gem 'jquery-rails'

$ bundle install

Require Bootstrap Javascripts in

需要 Bootstrap Javascripts

app/assets/javascripts/application.js:

应用程序/资产/javascripts/application.js:

//= require jquery
//= require bootstrap-sprockets

bootstrap-sprocketsand bootstrapshould not both be included in

bootstrap-sprockets并且bootstrap不应同时包含在

application.js

应用程序.js

. bootstrap-sprocketsprovides individual Bootstrap Javascript files (alert.js or dropdown.js, for example), while bootstrapprovides a concatenated file containing all Bootstrap Javascripts.

. bootstrap-sprockets提供单独的 Bootstrap Javascript 文件(例如,alert.js 或 dropdown.js),同时bootstrap提供包含所有 Bootstrap Javascript 的连接文件。

This will fix the error

这将修复错误

Copied @github

回答by Linda Kadz

I had the same problem

我有同样的问题

sass::syntaxerror: file to import not found or unreadable: config/variables.

, I opened a new css file (I called it custom.css) then copied all the css to the file. On application.css I removed the

,我打开了一个新的 css 文件(我称之为 custom.css),然后将所有的 css 复制到文件中。在 application.css 上我删除了

@import "config/variables" plus all the other @imports

@import "config/variables" 加上所有其他@imports

This worked for me, I hope it does work for you too!

这对我有用,我希望它也对你有用!

回答by meOn

This error mostly comes in rails 3.2.x versions. If you are using rails version 3.2 you have to specify a special version in your gem file like below:

此错误主要出现在 rails 3.2.x 版本中。如果您使用的是 rails 3.2 版,则必须在您的 gem 文件中指定一个特殊版本,如下所示:

gem 'rails', '3.2.0'
gem 'bootstrap-sass', '3.2.0.2'

It will resolve the problem for rails -v '3.2.0'

它将解决问题 rails -v '3.2.0'