Hi, all. I’ve started a new project and I’m having an issue with gulp-sass crashing gulp watch when selectors aren’t found.
I’ve tried figuring this out, but my node-fu isn’t too strong. I’ve narrowed it down to the sass() module in the cssTasks function sage/gulpfile.js at 8.5.0 · roots/sage · GitHub and I think it’s something do with the errLogToConsole.
I found this StackOverflow post, about a change in the way Gulp works from 1.x to 2.x. But I’m running gulp 3.9.1.
Has anyone else come across this issue? Thanks in advance.
The error message:
james@cthulhu:~/Development/example.com/site/web/app/themes/test-theme$ gulp
[06:33:49] Using gulpfile ~/Development/example.com/site/web/app/themes/test-theme/gulpfile.js
[06:33:49] Starting ‘clean’…
[06:33:49] Finished ‘clean’ after 6.48 ms
[06:33:49] Starting ‘default’…
[06:33:49] Starting ‘build’…
[06:33:49] Starting ‘wiredep’…
[06:33:49] Finished ‘default’ after 127 ms
[06:33:49] Finished ‘wiredep’ after 169 ms
[06:33:49] Starting ‘styles’…
assets/styles/sections/_section-hero.scss
Error: “.section–hero” failed to @extend “%bg-cover”.
The selector “%bg-cover” was not found.
Use “@extend %bg-cover !optional” if the extend should be able to fail.
on line 2 of assets/styles/sections/_section-hero.scss
>> @extend %bg-cover;
–^
events.js:160
throw er; // Unhandled 'error' event
^
Error: assets/styles/sections/_section-hero.scss
Error: ".section--hero" failed to @extend "%bg-cover".
The selector "%bg-cover" was not found.
Use "@extend %bg-cover !optional" if the extend should be able to fail.
on line 2 of assets/styles/sections/_section-hero.scss
>> @extend %bg-cover;
--^
at options.error (/home/james/Development/example.com/site/web/app/themes/test-theme/node_modules/node-sass/lib/index.js:283:26)
Where is %bg-cover actually defined? Can you try defining it on line 1 of _section-hero.scss and seeing if that clears the error. If it does then you might have simply included _section-hero.scss before you included the partial that contains its definition.
Hi, @cfx%bg-cover isn’t defined anywhere. But my issue relates to how gulp is handling this, rather than the definition itself.
Up until now, when I had an undefined or invalid Sass variable or css property, the gulp watch process would display the error and continue with the rest of the build.
Now, the gulp watch process crashes and I need to restart it when an error occurs. This is the issue I’m having, as I’d like it to just display the error and continue building, rather than crashing and requiring a restart.
I think this is something due to the gulp-sass module, but I haven’t been able to figure out how to catch this error and handle it properly, so that the gulp watch process doesn’t crash.
My experience has been that some errors fail gracefully and others simply don’t. Something like this generally isn’t reason enough for me to lose sight of my project and begin delving into gulp module source, especially when the error message itself gives you a way to allow the declaration to fail gracefully.
Thanks again for your reply. I’m not quite sure what you mean about the error message giving me a way to gracefully handle the exception so that gulp watch doesn’t crash.
I’ve tried modifying the cssTasks function as follows:
I know it’s not a major issue, but if I make a spelling mistake, or use an incorrect variable name, gulp watch is crashing and requires manual restarting each time, which is quite frustrating.
If someone has encountered this before and has solved it with some sort of exception handler, which prevents gulp watch from crashing, I’d be very grateful.