• お役立ち

Windows + Compass でコンパイルできない→.sass-cacheのファイルパス文字数が原因でした

  • このエントリーをはてなブックマークに追加
  • LINEで送る

備忘録を兼ねて。どうしてもcompassでscssファイルをコンパイルすることができず難儀してたのですが、コンパイル時に生成される.sass-cacheのファイルパスが255文字を超えるとエラーになるというのが原因でした…。

とある案件でCompassを導入していたものの、以下の様なエラーが出てどうしてもコンパイルできない。

cmd.exe /D /C call C:/Ruby200-x64/bin/compass.bat compile C:/Users/user/GitLocalRepositories/my-project/html/sass C:/Users/user/GitLocalRepositories/my-project/html/sass/sass/style.scss
 modified config.rb
    clean css
   delete css/style.css
    error sass/style.scss (C:/Ruby200-x64/lib/ruby/2.0.0/tempfile.rb:146:in `initialize': No such file or directory - C:/Users/user/GitLocalRepositories/my-project/html/sass/.sass-cache/75fcaf1b4852ceb732871195e41567cc2a7d8997/C%058/Ruby200-x64/lib/ruby/gems/2.0.0/gems/compass-core-1.0.3/stylesheets/compass/typography/lists/_horizontal-list.scssc20160816-12064-6frnep)
Compilation failed in 1 files.

Process finished with exit code 1

ちなみに自分の環境はこんな感じ。

  • Windows10
  • PhpStorm 2016.2
  • ruby 2.0.0p647 (2015-08-18) [x64-mingw32]
  • Compass 1.0.3 (Polaris)

いろいろ調べてみたところ、コンパイル時に生成される.sass-cacheのファイルパスが255文字を超えるとエラーが出るんだそうな*

compass compile .sasss-cache file full path length over 255 will failed · Issue #1791 · Compass/compass

関連する記事についてるレスを読んでいると、どうやらsassやcompassのバージョンを戻すのが有効だという話も。

ただ、バージョンを戻すのはちょっと避けたかったので、結局下記の記事を参考に、.sassのキャッシュを無効化することで解決しました。

Compassのキャッシュ「.sass-cache」の書き出しをコントロールする方法 | Webデザインのタネ

最終的に動くようになった状態のconfig.rbがこちら。最終行のcache = falseがポイントです。

require 'compass/import-once/activate'
# Require any additional compass plugins here.

# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "css"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"

# You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed

# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true

# To disable debugging comments that display the original location of your selectors. Uncomment:
line_comments = false


# If you prefer the indented syntax, you might want to regenerate this
# project again passing --syntax sass, or you can uncomment this:
# preferred_syntax = :sass
# and then run:
# sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass

Encoding.default_external = 'utf-8'

cache = false

今回はたまたまコンパイル対象のファイル数やボリュームがさほどでもなかったのでこれで解決しましたが、毎回そうとも限らないですよね。前述のページ見てると、キャッシュファイルの置き場も指定できるみたいなんで、今後はそうしたやり方も必要になるかもしれないです。

注釈:
ちなみにファイルパスの文字数制限は、Rubyの仕様ではなく、Windowsの仕様です。

Windowsのファイル名最大文字数は?ファイル名が半角や全角の場合は? @
コンピュータ系サラリーマンブログ: Windowsのファイル名最大文字数は?ファイル名が半角や全角の場合は?

星虹思械BRICOLEUR

関連コンテンツ