Rails 3应用程序中的Sass导入错误-“找不到或无法读取的导入文件:罗盘”

ruby-on-rails CSS

老丝阿飞

2020-03-23

我有一个成功运行过的Rails 3应用程序compass init rails ./ --using blueprint我可以@import从/ stylesheets目录中归档文件,但是尝试时出现错误@import compass

现在,该应用程序具有两个简单的sass文件:

common.scss

$body-background: blue;

main.scss

@import "common";
//@import "compass";

body { 
  background: $body-background; 
}

@import "compass"注释掉行后,此方法有效-我得到了蓝色背景,所以我知道Sass在起作用。

如果我取消注释该行,并尝试导入compassblueprint其他任何内容,则会收到这样的错误。

Syntax error: File to import not found or unreadable: compass.
              Load paths:

                /Users/eric/path/to/myrailsapp/app/stylesheets
        on line 2 of /Users/eric/path/to/myrailsapp/app/stylesheets/main.scss

1: @import "common";
2: @import "compass";
3: 
4: body { 
5:  background: $body-background; 
6: }

我可能不得不明确地告诉Sass在哪里可以找到Compass gem,所以我add_import_path在config / compass.rb中添加了一行:

require 'compass'
require 'html5-boilerplate'

project_type = :rails
project_path = RAILS_ROOT if defined?(RAILS_ROOT)
add_import_path "/Library/Ruby/Gems/1.8/gems/"  # unfortunately this has no effect

http_path = "/"
css_dir = "public/stylesheets"
sass_dir = "app/stylesheets"
images_dir = "public/images"
javascripts_dir = "public/javascripts"
cache_dir = "tmp/sass-cache"

http_images_path = "/images"
http_stylesheets_path = "/stylesheets"
http_javascripts_path = "/javascripts"

我已经搜寻了两天,无法确定为什么我的基本@import陈述会出现这个问题如何告诉Sass在哪里可以找到Compass和Blueprint库?

第2837篇《Rails 3应用程序中的Sass导入错误-“找不到或无法读取的导入文件:罗盘”》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

6个回答
Pro神奇 2020.03.23

我这样修复此错误:

在application.rb我有

Bundler.require(:default, Rails.env) if defined?(Bundler)  

并更改为

Bundler.require(:default, :assets, Rails.env) if defined?(Bundler)

这是将项目从3.0.3更新到3.2.13之后的结果

老丝小哥梅 2020.03.23

Sass中的@import命令导入.scss或.sass文件,而不是.css文件。

似乎在安装中缺少某些内容。(也许是该行compass install blueprint?),我在这里按照以下步骤操作:http : //compass-style.org/reference/blueprint/,但无法重新创建问题。

小胖Gil 2020.03.23

好吧,在令人惊叹的克里斯·埃普斯坦(Chris Eppstein)的帮助下,我找到了令人反感的路线。config/environments.rb我的这一行:

Sass::Plugin.options[:template_location] = {
"#{RAILS_ROOT}/app/stylesheets" => "#{RAILS_ROOT}/public/stylesheets"
}

对于当前版本的Rails(我有3.0.7)和Compass(0.11.1),此行不是必需的我按照教程学习后添加了它。如果sass找不到指南针,可能是因为这条线弄乱了您的Sass::Plugin.options[:template_location]

神乐 2020.03.23

我将其撞到头后解决了这个错误

我在我的application.rb中从以下位置注释了这一行:

Bundler.require(*Rails.groups(:assets => %w(development test))) if defined?(Bundler)

并没有评论:

Bundler.require(:default, :assets, Rails.env) if defined?(Bundler)    

我正在使用Rails 3.2.11

GO 2020.03.23

我收到此错误。

我将application.rb中的这一行从以下位置更改:

Bundler.require(:default, Rails.env) if defined?(Bundler)

至:

Bundler.require(*Rails.groups(:assets => %w(development test))) if defined?(Bundler)

另外,请确保文件的名称为something.css.sass而不是something.sass

还有一件事,我的配置目录中有一个旧的指南针.rb文件,而在Rails 3.2中则不需要。删除也为我解决了这个问题。

卡卡西 2020.03.23

我通过切换到compass-railsgem而不是compassGemfile中gem来解决了这个问题(不要忘记重启服务器)。以防万一有人碰到这里。

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android