25

This is in VS 2013 update 3. I declared the variables in _variables.scss:

$fontFamily: "Times New Roman", Times, serif;
$shapeColor: #ACAEAA;
...

Then it is imported at the very beginning of my main.scss as below:

@import '_variables.scss';
@import '_base.scss'; // not able to use any variables declared in _variables.css

In main.scss, all the global variables work fine. However, none of the global variables works in _base.scss. VS refuses to compile them and they are marked as Undeclared Variable. Is this a VS compiler issue or I am doing something wrong?

Quentin
  • 1,310
  • 18
  • 30

1 Answers1

55

If you add the following to _base.scss and your intellisense should behave.

/// <reference path="_variables.scss" />

I have written a post on this if you need more info Get intellisense in sass/less files in visual-studio

Colin Bacon
  • 15,436
  • 7
  • 52
  • 72
  • The squiggly lines are gone and intellisense works. However, it still shows `_base.scss` compilation failed: The service failed to respond to this request. Possible cause: Syntax Error! – Quentin Sep 09 '14 at 20:36
  • The CSS actually works but the compilation error message could be misleading. Why is it working but still showing error messages? – Quentin Sep 09 '14 at 20:37
  • I sometimes get this when I save in a partial file (one prefixed with `_`). But if you save `main.scss` it will compile successfully. Not sure why it does this, maybe a bug in Web Essentials. – Colin Bacon Sep 11 '14 at 20:52
  • Works great! If the referenced file is inside a folder, make sure you map the correct path _directly from the referencing file_. In our company, we have `@import "partials/helpers/_variables` and `@import "partials/_settings` in "application.scss", so in _settings.scss we need `/// `. – Gilad Barner Dec 23 '15 at 10:05
  • 7
    Do you have to do this to *every* file individually? – JMK Nov 13 '17 at 16:56
  • 2
    Like @JMK, I'm wondering if there's a more centralized way to write this in one spot and have it apply to every file? See this question: https://stackoverflow.com/q/59329833/422845 – jbyrd Jan 20 '20 at 16:40