Search code examples
rubylinuxsasscompassnomethoderror

Undefined method `has?' for Sass::Util:Module (NoMethodError) - Error on Debian with Ruby, Sass, Compass


I searched for a solution to the following problem, but I couldn't find anything. So I hoped that you could help me. Thank you.

I have:

  • Debian Stretch (distro: Debian GNU/Linux 9.7, kernel: Linux 4.9.0-8-amd64 (x86_64));
  • Apache NetBeans 10 (incubating) - the snap installed from https://snapcraft.io/netbeans;
  • PHP 7.1.


I installed (by inspiring myself from this page:

  • Ruby (with: sudo apt install ruby-full);
  • Sass (with sudo gem install sass);
  • Compass (with sudo gem install compass);

and checked their versions:

# ruby --version
ruby 2.3.3p222 (2016-11-21) [x86_64-linux-gnu]

# sass --version
Ruby Sass 3.7.3

# compass --version
Compass 1.0.3 (Polaris)
Copyright (c) 2008-2019 Chris Eppstein

Please note that I have null experience with Ruby.


I have the following NetBeans settings:

*) In the tab "Tools > Options > HTML/JS > CSS Preprocessors":

Sass Path: /usr/local/bin/sass

I also tried:

Sass Path: /usr/local/bin/scss

*) In the tab "File > Project Properties > CSS Preprocessors > Sass":

Input: /web/src/Application/assets/scss
Output: /web/public/assets/css
Compiler Options: --compass -E "UTF-8" --trace --no-cache


Backtrace:

When I tried to compile the .scss files (in order to create the corresponding .css files) I received an error for each of them. This is the backtrace for the first .scss file:

"/usr/local/bin/sass" "--cache-location" "/home/<my-username>/snap/netbeans/common/cache/10.0/sass-compiler" "--sourcemap=none" "--compass" "-E" "UTF-8" "--trace" "--no-cache" "<my-path-to-project-root>/web/src/Application/assets/scss/fonts.scss" "<my-path-to-project-root>/web/public/assets/css/fonts.css"
/var/lib/gems/2.3.0/gems/compass-core-1.0.3/lib/compass/core/sass_extensions/functions/urls.rb:5:in `has?': undefined method `has?' for Sass::Util:Module (NoMethodError)
Did you mean?  hash
               Hash
    from /var/lib/gems/2.3.0/gems/compass-core-1.0.3/lib/compass/core/sass_extensions/functions/urls.rb:9:in `included'
    from /var/lib/gems/2.3.0/gems/sass-3.7.3/lib/sass/script/functions.rb:627:in `include'
    from /var/lib/gems/2.3.0/gems/sass-3.7.3/lib/sass/script/functions.rb:627:in `include'
    from /var/lib/gems/2.3.0/gems/compass-core-1.0.3/lib/compass/core/sass_extensions/functions.rb:23:in `<module:Functions>'
    from /var/lib/gems/2.3.0/gems/compass-core-1.0.3/lib/compass/core/sass_extensions/functions.rb:19:in `<top (required)>'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /var/lib/gems/2.3.0/gems/compass-core-1.0.3/lib/compass/core/sass_extensions.rb:9:in `<top (required)>'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /var/lib/gems/2.3.0/gems/compass-core-1.0.3/lib/compass/core.rb:68:in `<top (required)>'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /var/lib/gems/2.3.0/gems/compass-1.0.3/lib/compass.rb:14:in `block in <top (required)>'
    from /var/lib/gems/2.3.0/gems/compass-1.0.3/lib/compass.rb:13:in `each'
    from /var/lib/gems/2.3.0/gems/compass-1.0.3/lib/compass.rb:13:in `<top (required)>'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
    from /var/lib/gems/2.3.0/gems/sass-3.7.3/lib/sass/exec/sass_scss.rb:238:in `load_compass'
    from /var/lib/gems/2.3.0/gems/sass-3.7.3/lib/sass/exec/sass_scss.rb:49:in `process_result'
    from /var/lib/gems/2.3.0/gems/sass-3.7.3/lib/sass/exec/base.rb:50:in `parse'
    from /var/lib/gems/2.3.0/gems/sass-3.7.3/lib/sass/exec/base.rb:18:in `parse!'
    from /var/lib/gems/2.3.0/gems/sass-3.7.3/bin/sass:13:in `<top (required)>'
    from /usr/local/bin/sass:22:in `load'
    from /usr/local/bin/sass:22:in `<main>'
Done.


urls.rb file:

This is the beginning content of the file specified in the backtrace (/var/lib/gems/2.3.0/gems/compass-core-1.0.3/lib/compass/core/sass_extensions/functions/urls.rb):

module Compass::Core::SassExtensions::Functions::Urls


  def self.has?(base, instance_method)
    Sass::Util.has?(:instance_method, base, instance_method)
  end

  def self.included(base)
    base.send(:include, StylesheetUrl) unless has?(base, :stylesheet_url)
    base.send(:include, FontUrl) unless has?(base, :font_url)
    base.send(:include, ImageUrl) unless has?(base, :image_url)
    base.send(:include, GeneratedImageUrl) unless has?(base, :generated_image_url)
  end

Solution

  • The problem:

    The problem resided in the fact, that I installed the Debian's package ruby-full, along with Sass and Compass as ruby gems, e.g. using the gem command-line tool.

    The solution:

    By default, Debian 9.7 (Stretch) has the Ruby interpreter installed (version 2.3). The package name is ruby2.3. In order to be able to correctly compile .scss files and use the functions provided by Compass, only the packages ruby-sass and ruby-compass must be additionaly installed.

    Followed steps:

    I) First, using Terminal, I proceeded with the uninstallation of the previously wrongly installed libraries:

    I uninstalled the package ruby-full:

    $ sudo apt purge ruby-full
    $ sudo apt autoremove
    

    I uninstalled the Sass and Compass gems:

    $ sudo gem uninstall compass
    $ sudo apt autoremove
    
    $ sudo gem uninstall sass
    $ sudo apt autoremove
    

    II) Then I proceeded with the installation of the new packages:

    I checked the status of the Debian's default Ruby version:

    $ apt list ruby2.3*
    ruby2.3/stable,now 2.3.3-1+deb9u4 amd64 [installed]
    ruby2.3-dev/stable,now 2.3.3-1+deb9u4 amd64 [installed,automatic]
    ruby2.3-doc/stable,now 2.3.3-1+deb9u4 all [installed,automatic]
    

    I installed the new packages:

    $ apt update
    $ apt install ruby-sass
    $ apt install ruby-compass
    

    I checked the versions of both installed packages:

    $ sass --version
    Sass 3.4.23 (Selective Steve)
    
    $ compass --version
    Compass 1.0.3 (Polaris)
    Copyright (c) 2008-2019 Chris Eppstein
    

    I checked the locations of the installed executable files:

    $ which sass
    /usr/bin/sass
    
    $ which compass
    /usr/bin/compass
    

    III) In the end, in Netbeans, in the tab Tools > Options > HTML/JS > CSS Preprocessors, I set the Sass Path to /usr/bin/sass.

    That was it. The Sass files are correctly compiled and the Compass functions are correctly recognized and called.