Search code examples
node.jsvisual-studiotypescriptgulp

Error running Gulpfile from Visual Studio 2015 task runner


I am building a gulpfile to use in my ASP.NET winforms project. So far I have the following in the package.json

{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"devDependencies": {
  "browserify": "^13.1.0",
  "del": "2.2.0",
  "gulp": "^3.9.1",
  "gulp-sourcemaps": "^2.2.0",
  "gulp-typescript": "^3.0.2",
  "tsify": "^2.0.2",
  "vinyl-source-stream": "^1.1.0"
 }
}

and the gulp file has

/// <binding BeforeBuild='default' />
/*
 This file in the main entry point for defining Gulp tasks and using Gulp      plugins.
  Click here to learn more. http://go.microsoft.com/fwlink/?LinkId=518007
*/

var gulp = require('gulp');

var del = require('del');
var ts = require("gulp-typescript");
var tsProject = ts.createProject("tsconfig.json");
var sourcemaps = require('gulp-sourcemaps');

gulp.task('default', function () {
  // place code for your default task here
});

My node version is 6.9.1

If I run this from the command line ('gulp') it works fine. But in the Visual Studio task runner, it fails to load, and in the out put I see the following error. This error starts after I add the line var sourcemaps = require('gulp-sourcemaps');

 Failed to run "H:\dev\myproj\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
H:\dev\myproj\node_modules\gulp-sourcemaps\node_modules\strip-bom\index.js:2
module.exports = x => {
                    ^
SyntaxError: Unexpected token >
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (H:\dev\myproj\node_modules\gulp-sourcemaps\src\init.js:10:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

Also adding var tsify = require("tsify"); I get another error...

Failed to run "H:\dev\myproject\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
TypeError: Object #<Object> has no method 'debuglog'
    at Object.<anonymous> (H:\dev\myproject\node_modules\tsify\index.js:4:32)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (H:\dev\myproject\gulpfile.js:17:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

Anyone have any ideas why I am getting this?

Thanks in advance!


Solution

  • My problem was I didn't realize Visual Studio has it's own (way out of date) version of the node tools (installed within the Visual Studio folders somewhere). How untidy!

    To make it use the "global" node tools, I could go to the menu Tools | Options | Projects and Solutions | External Web Tools and move the $(PATH) to be before the $(DevEnvDir)\* locations. After I did this, my Gulp file would load.

    The other option may have been to update the Visual Studio node tools via the Tools | Extensions and Updates, but (I think) I'd prefer to use the same external tools I will use outside of Visual Studio.