Working on a site, I went to run my grunt command to compile sass, I got an error.

Running "sass:dist" (sass) task
/usr/local/Cellar/ruby/2.4.2_1/lib/ruby/2.4.0/rubygems.rb:271:in `find_spec_for_exe': can't find gem sass (>= 0.a) (Gem::GemNotFoundException)
    from /usr/local/Cellar/ruby/2.4.2_1/lib/ruby/2.4.0/rubygems.rb:299:in `activate_bin_path'
    from /usr/local/bin/sass:22:in `<main>'
Warning: Exited with error code 1 Use --force to continue.

No good, right? And googling around for that didn't help me at all until I drilled down and realized the sass error was a Ruby error.

Upgrade Ruby

First, install Homebrew. I know there are many other ways to handle installs on Macs, but Homebrew has been my go-to for a few years. It makes my life easier.

Once Homebrew is installed run the following command: brew install rbenv ruby-build

If this gives you an error, like missing xcrun, then run this: xcode-select --install

Once you have rbenv installed, it's time to upgrade ruby:

rbenv install 2.4.2
rbenv global 2.4.2

Awesome! But grunt still doesn't work. And this is because Sass isn't installed.

Install Sass

This should be easy, right? sudo gem install -n /usr/local/bin sass and off you go. The problem is you may get this error:

ERROR:  While executing gem ... (TypeError)
    no implicit conversion of nil into String

Not so helpful. The magic here is going backwards to go forward. Update your gems first: sudo gem update --system and then run the installer for sass.

Why Did This Happen?

The short answer is that Mac changed versions and everything got out of sync. I'm not a system code expert so I can't explain it better than that.

How you fix these things is by understanding how to logically step backwards through the errors. Most of the time, we see it as "Grunt says Sass is broken!" and the trick here is to ask yourself "What runs Sass?" and the answer is "Ruby." So instead of looking up "Why can't I run sass on grunt?" we look up "Ruby can't compile SCSS on Mac High Sierra" because that's the ultimate answer.

Walking backwards is the secret sauce for all solutions with software, I feel. Why can't Grunt run Sass? Because Ruby can't compile? Why can't Ruby compile SCSS? Let's reinstall Sass! Oh wait, that has an error. Okay, let's upgrade Ruby. Oh that has an error too? Let's solve that.

It's not fun, unless you're me and think snarling at a laptop in the conference room of your friends' office is cheerful.

Reader Interactions

%d bloggers like this: