Gulp Build Not Working In Visual Studio But Works On Command Line
I’ve been working quite a bit with a project recently that uses gulp to build the CSS and JavaScript files in Visual Studio from the Task Runner Explorer. Recently, this build suddenly stopped working and I couldn’t figure out why. It ran just fine from the command prompt, but in Task Runner Explorer, it threw all kinds of errors. This is an older project and requires an older version of NodeJs and gulp to be installed.
What I wasn’t aware of is that Visual Studio has it’s own version of NodeJs that is uses for Task Runner Explorer work by default. I would surmise that during a recent VS update, it updated that internal version to one that wasn’t compatible with the current structure of the project’s gulpfile and SASS build.
It took me a while to figure out what was going wrong, but the fix was relatively simple. You need to override the version of Node that Visual Studio is using and force it to use the same version that the command prompt uses. To do this, open up the External Web Tools configuration in Visual Studio’s Options. Under the “Locations of external tools”, add a line at the top that points to your local NodeJs install (the one the command prompt uses).
Restart Visual Studio and it should solve the problem.