Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Undefined variable errors only in watch mode. #2560

Closed
hangoocn opened this issue Dec 8, 2018 · 5 comments
Closed

Undefined variable errors only in watch mode. #2560

hangoocn opened this issue Dec 8, 2018 · 5 comments

Comments

@hangoocn
Copy link

hangoocn commented Dec 8, 2018

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?

@hangoocn hangoocn changed the title Compiling undefined variable errors only in watch mode. Undefined variable errors only in watch mode. Dec 9, 2018
@hangoocn
Copy link
Author

hangoocn commented Dec 9, 2018

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.

@hangoocn hangoocn closed this as completed Dec 9, 2018
@hangoocn hangoocn reopened this Dec 9, 2018
@hangoocn
Copy link
Author

hangoocn commented Dec 9, 2018

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?

@Epskampie
Copy link

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

@idileepd
Copy link

idileepd commented Jan 17, 2020

convert all file names with beginning "_"

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

@xzyfer
Copy link
Contributor

xzyfer commented Jan 30, 2020

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

@xzyfer xzyfer closed this as completed Jan 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants