Jasper de Vries
Jasper de Vries

Reputation: 20253

How to use Sass with NetBeans on Linux / macOS

I used to be able to install and use Sass with NetBeans 8 as described in the top answer on How to use SASS with Netbeans 8.0.1

Now, with the current version of Sass (1.14.1), installing is different. Basically just download and untar. That's done and I've pointed NetBeans to the correct location. But this current version of Sass won't run correctly from NetBeans:

"/opt/dart-sass/sass" "--cache-location" 
"/home/jasper/.cache/netbeans/8.2/sass-compiler"
"path_to_my.scss" "path_to_my.css"
Could not find an option named "cache-location".

This error is also covered by Sass output error in Netbeans 8.2 where they are using Windows.

I tried to add the cache location parameter (similar to the solution for Windows) to this line in the sass file:

exec "$path/src/dart" --no-preview-dart-2 "-Dversion=1.14.1" "$path/src/sass.dart.snapshot" "$@"

but I could not get it working (same error keeps appearing).

Anybody any ideas on how to get Sass 1.14.1 working from NetBeans 8.2 on Linux (Ubuntu)?

Upvotes: 3

Views: 2149

Answers (2)

Jasper de Vries
Jasper de Vries

Reputation: 20253

The issue is that --cache-location is no longer supported and should be removed. All of the original parameters are used by "$@". To remove the first two parameters, you should be able to use "${@:3}" (see Process all arguments except the first one (in a bash script)), but somehow that resulted into a "Bad substitution" error for me. So I opted to use shift 2 to remove them:

#!/bin/sh
# Copyright 2016 Google Inc. Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

# This script drives the standalone Sass package, which bundles together a Dart
# executable and a snapshot of Sass. It can be created with `pub run grinder
# package`.

follow_links() {
  file="$1"
  while [ -h "$file" ]; do
    # On Mac OS, readlink -f doesn't work.
    file="$(readlink "$file")"
  done
  echo "$file"
}

# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
path=`dirname "$(follow_links "$0")"`
shift 2
exec "$path/src/dart" --no-preview-dart-2 "-Dversion=1.14.1" "$path/src/sass.dart.snapshot" "${@}"

Make sure to keep the original file and create a copy to only be used with NetBeans and make the change there.

macOS (Home Brew)

If you are looking for the Dart Sass install location (after installing it with Home Brew), it is located here:

/usr/local/Cellar/sass/{version}/bin

macOS (node.js)

When using node.js, you will run into the "env: node: No such file or directory" issue.

To work around that I created (make sure you make it executable (chmod a+x)):

/usr/local/lib/node_modules/sass/sass_nb.sh

and added:

#!/bin/zsh

export PATH="$PATH:"/usr/local/bin/
shift 3
sass ${@}

NetBeans 11+

On NetBeans 11 and 12 I had to use shift 3 instead of shift 2.

Upvotes: 1

Alex
Alex

Reputation: 5904

My response is based heavily on Jasper de Vries'one:

It seems that Netbeans simply adds some additional parameters that are no longer supported by sass compiler.

In my case the complete command issued by Netbeans was:

"/home/alex/tools/dart-sass/sass" "--cache-location" "/home/alex/snap/netbeans/common/cache/12.0/sass-compiler" "--debug-info" "/home/alex/projects/alexgheorghiu.com/web/aaa.scss" "/home/alex/projects/alexgheorghiu.com/web/aaa.css"

So the first 3 parameters

"--cache-location" "/home/alex/snap/netbeans/common/cache/12.0/sass-compiler" "--debug-info"

must be "deleted" or ignored.

So you need to either alter the sass file or make a copy of it (safest way) and add

shift 3

instruction.

So if you start from original version like:

#!/bin/sh

# This script drives the standalone dart-sass package, which bundles together a
# Dart executable and a snapshot of dart-sass.

follow_links() {
  file="$1"
  while [ -h "$file" ]; do
    # On Mac OS, readlink -f doesn't work.
    file="$(readlink "$file")"
  done
  echo "$file"
}

# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
path=`dirname "$(follow_links "$0")"`
exec "$path/src/dart" "$path/src/sass.snapshot" "$@"

You need to end up with something like:

#!/bin/sh

# This script drives the standalone dart-sass package, which bundles together a
# Dart executable and a snapshot of dart-sass.

follow_links() {
  file="$1"
  while [ -h "$file" ]; do
    # On Mac OS, readlink -f doesn't work.
    file="$(readlink "$file")"
  done
  echo "$file"
}

# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
path=`dirname "$(follow_links "$0")"`
shift 3
exec "$path/src/dart" "$path/src/sass.snapshot" "$@"

An interesting aspect is that this bug is known by Netbeans developers (See: Could not find an option named "cache-location") but I was not able to achieve that because under my Xubuntu 18 the Netbeans is a "snap" and therefore it's netbeans.conf file is read only. But in case you CAN modify that file it might be a cleaner solution.

Upvotes: 0

Related Questions