Node-sass: Undefined variable errors only in watch mode.

Created on 8 Dec 2018  路  5Comments  路  Source: sass/node-sass

main.scss:

@import "test1"
@import "test2"

test1.scss:
$w: white
test2.scss
.c{color: $w}
Run in win10 cmd:
node-sass main.scss main.css
No error, generated content:
.p {color: white; }
But if I run the watcher:
node-sass --watch main.scss main.css
Then make changes to test2.scss and save, error:

{
  "status": 1,
  "file": "C:/Users/xxx/Desktop/test2.scss",
  "line": 1,
  "column": 10,
  "message": "Undefined variable: \"$w\".",
  "formatted": "Error: Undefined variable: \"$w\".\n        on line 1 of Test2.scss\n>> .p{color:$w}\n   ---------^\n"
}

  • NPM version (npm -v): 6.4.1
  • Node version (node -v): v8.12.0
  • Node Process (node -p process.versions):
    { http_parser: '2.8.0',
    node: '8.12.0',
    v8: '6.2.414.66',
    uv: '1.19.2',
    zlib: '1.2.11',
    ares: '1.10.1-DEV',
    modules: '57',
    nghttp2: '1.32.0',
    napi: '3',
    openssl: '1.0.2p',
    icu: '60.1',
    unicode: '10.0',
    cldr: '32.0',
    tz: '2017c' }
  • Node Platform (node -p process.platform): win32
  • Node architecture (node -p process.arch):x64
  • node-sass version (node -p "require('node-sass').info"): Cannot find module 'node-sass'
  • npm node-sass versions (npm ls node-sass): C:\Users\xxx\Desktop`-- (empty)
  • node-sass version(ndoe-sass -v):
    node-sass 4.10.0 (Wrapper) [JavaScript]
    libsass 3.5.4 (Sass Compiler) [C/C++]

I know if I add @import "test1" to "test2.scss" it would not complain, but I wonder why this error only happens in watch mode?

Module - Watcher

All 5 comments

Finally, the problem is solved by adding '_' prefix to the partials, like changing sass2.scss to _sass2.scss.
But I still feel it might be better to make watch mode and non-watch mode has the same behavior.

I need to reopen this issue because it is not an issue in dart-sass cli, is this by design or a bug? Why does this only happen in watch mode?

Having the same problem. Would appreciate it if node-sass worked the same in non-watch and watch mode.

convert all file names with beginning "_"

example:
typography.scss >> to >> _typography.scss

This is by design. When a file is not prefixed with an _ it needs to be able to compile independently. Since test2 depends on test1 is should be named _test2. This lets Sass know that when this file is changed Sass should compile the parent files that import it.

See https://sass-lang.com/guide#topic-4

Was this page helpful?
0 / 5 - 0 ratings