问题 rake assets:precompile throws Sass :: SyntaxError:“* /”之后的CSS无效


我希望这不是一个重复的问题;我在SO上尝试了其他解决方案,没有任何效果

当我的应用程序推送到Heroku时,推送失败,因为application.css无法编译。

我的终端输出:

Running: rake assets:precompile
rake aborted!
Sass::SyntaxError: Invalid CSS after " */": expected selector, was "@font-face"
(in /tmp/build_17e92975-ae8d-446f-8678-110eeeccfb64/app/assets/stylesheets/adminsite/application.css)
(sass):1845

尝试解决方案

我搜索并删除了../stylesheets/adminsite/目录中@ font-face之前的每个“* /”实例。同样的问题和结果。

我试过设置:

  config.assets.compile = true

......同样的问题

编辑

这是我的application.css(不是应用程序级别1,而是adminsite目录中失败的那个)

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the top of the
 * compiled file, but it's generally better to create a new file per style scope.
 *
 *= require jquery.ui.all
 *= require_self
 *= require normalize
 *= require ./global/plugins/bootstrap/css/bootstrap
 *= require ./global/plugins/uniform/css/uniform.default
 *= require ./global/plugins/bootstrap-switch/css/bootstrap-switch
 *= require ./global/css/components
 *= require ./global/css/plugins
 *= require ./global/plugins/simple-line-icons/simple-line-icons
 *= require ./admin/layout/css/layout
 *= require ./admin/layout/css/themes/light2
 *= require ./admin/layout/css/custom
 */

通过删除和重新整理,我发现了

*= require ./global/plugins/font-awesome/scss/font-awesome

从该列表的底部开始的是3,导致它失败。我现在可以在本地运行了

rake assets:precompile --trace RAILS_ENV=production

但是我无法使用

git push herokunb newbeta:master

解决了:

这是字体真棒CSS。删除它需要修复它。这个问题似乎没有解决,只是由于我自己的git错误。


9198
2017-09-08 10:33


起源

它是临时目录中的文件,而不是项目目录。删除该文件,然后重试。如果仍然抱怨,请打开文件并在第1845行(或投诉的任何地方)发布内容。 - Substantial
你可以发布你的application.css吗? - Richard Peck
发布了application.css。没有“/ tmp / build_17e92975-ae8d-446f-8678-110eeeccfb64 /”...似乎是在使用rake时构建和删除的? - Will Taylor
请将您的解决方案作为答案发布并接受。 - Substantial
如果删除字体很棒的CSS,则可以成功部署应用程序。但是你的所有页面都没有CSS。你如何解决? - Jiayi Zhou


答案:


即使你找到了修复它的方法,我也会分享我的解决方案,因为我遇到了同样的问题而且调试起来有点困难。

你可能正在使用 rails 3.2, sass-rails 3.2和 font-awesome-sass 4.1。

事实证明, rails  3.2 使用 sass-rails  3.2.6,这取决于 sass > = 3.1。但是,它看起来像 sass 3.1不兼容 font-awesome  4.1,所以我明确地设定了 sass 宝石使用我的版本3.2 的Gemfile

gem 'sass-rails', '~> 3.2.6'
gem 'sass', '~> 3.2.0'

希望这有助于某人! ;)


11
2017-09-12 18:18



在底层之后我遇到了同样的问题,不同的版本 sass gem从3.3.10更新到3.4.9。在Gemfile中明确设置它修复它: gem 'sass', '~> 3.3.10' - Curtis
更新 font-awesome-sass 为我工作 - laffuste


破坏事物的文件是字体真棒CSS。从application.css的“require”行中删除它允许预编译工作。

这样做的方法是首先删除所有预编译需求字段,显示它将编译,然后慢慢添加需要字段以查看它中断的位置。

(感谢所有帮助解决这个问题的人。)


0
2017-09-08 17:05





对我来说,我忘了在班级登录前添加#。

它应该是

#sign-in 
  (your code)

0
2018-05-05 23:48





我是rails的新手,在推送到heroku时遇到了类似的问题。一位朋友看了我的application.css文件,注意到我有

*= require bootstrap 

*= require bootstrap-datetimepicker

以下 */

删除它们让我成功推动。


0
2018-06-04 00:39





我也遇到了类似的问题,偶然发现了这个问题。对我来说,我离开了我的一个CSS语句的结尾。添加它,我在几分钟内恢复。


0
2017-07-23 04:47





解决此问题的另一种方法是明确告诉资产管道使用资产的css版本而不是scss版本。例如,如果您在application.scss中导入.scss文件,如下所示:

@import "angular-material";      # this will use scss version of the asset

您也可以告诉它使用css版本,如下所示:

@import "angular-material.css";  # this will use the css version

大多数供应商都提供scss和css版本,因此依赖css版本的资产非常有用,尤其是在使用供应商资产时。记住一切都将是预编译并最终变得丑化,所以你使用scss或css它们都会变得相同。


0
2018-04-17 20:22