1

I am building a gulpfile to use in my aps.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!

peterc
  • 6,921
  • 9
  • 65
  • 131

2 Answers2

5

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.

peterc
  • 6,921
  • 9
  • 65
  • 131
0

After some investigate with me facing the same issue, it seems to be a problem with version compatibility between your nodejs install, and your package dependency "strip-bom".

An adhoc fix is to change from:

module.exports = x => {

to:

module.exports = function (x) {

You might want to check this out: Gulp-Sourcemaps, SyntaxError: Unexpected token >

That seems to solve the issue for me, but not such a nice method.


The problem is that you might be running an old version of node. Try to use the command node -v or nodejs -v to check your version.

Though it might not be your case, but great for others to come by and see this, Debian/Ubuntu actually has an an outdated version of node on its package manager "apt-get". So it is highly possible that you're still running an old version such as 0.10.25.

The real fix I'd recommend (which I ended up doing), is to upgrade your node version. As of current date, version 6.9.1 seems to be the latest stable.

You can check the install guide at the nodejs official website here:

https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

Community
  • 1
  • 1
Thomas Cheng
  • 695
  • 12
  • 26