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 -v): 6.4.1node -v): v8.12.0node -p process.versions):node -p process.platform): win32node -p process.arch):x64node -p "require('node-sass').info"): Cannot find module 'node-sass'npm ls node-sass): C:\Users\xxx\Desktop`-- (empty)ndoe-sass -v):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?
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.