7

So I've upgraded to Visual Studio 16.6.3. When I go to the Task Runner Explorer it doesn't load my gulp file, in the Task Runner Output Window I can see...

Failed to run "E:\Projects\...\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
fs.js:35
} = primordials;
    ^
ReferenceError: primordials is not defined
    at fs.js:35:5
    at req_ (E:\Projects\...\node_modules\natives\index.js:143:24)
    at Object.req [as require] (E:\Projects\...\node_modules\natives\index.js:55:10)
    at Object.<anonymous> (E:\Projects\...\node_modules\graceful-fs\fs.js:1:37)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)

I then google this find this is due to an incompatibility between node 12 and gulp 3 with advice to upgrade to version 4. So I update my package.json file and change from "gulp": "3.9.1" to "gulp": "4.0.2". When I go to the task explorer, I see the following in the Task Runner Output Window ...

Failed to run "E:\Projects\...\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
AssertionError [ERR_ASSERTION]: Task function must be specified
    at Gulp.set [as _setTask] (E:\Projects\...\node_modules\undertaker\lib\set-task.js:10:3)
    at Gulp.task (E:\Projects\...\node_modules\undertaker\lib\task.js:13:8)
    at Object.<anonymous> (E:\Projects\...\gulpfile.js:86:6)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at requireOrImport (E:\Projects\...\node_modules\gulp\node_modules\gulp-cli\lib\shared\require-or-import.js:19:11) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='

I google this and the advice is to downgrade gulp to version 3... Just once I would like to open the Task Runner Explorer and not spend 4 hours trying to solve dependency issues.

Also running "npm install" from the Visual Studio Package Manager Console inside Visual Studio (elevated or not) just seems to result in a bunch of permission errors. I could only successfully run npm install from an elevated powershell window.

Anyone have a solution for these issues?

Package.json is as follows...

{
  "version": "1.0.0",
  "name": "asp.net",
  "private": true,
  "devDependencies": {
    "del": "4.1.1",
    "gulp": "3.9.1",
    "gulp-concat": "^2.6.1",
    "gulp-config": "0.3.0",
    "gulp-cssmin": "^0.2.0",
    "gulp-csso": "1.1.0",
    "gulp-htmlmin": "5.0.1",
    "gulp-imagemin": "2.4.0",
    "gulp-less": "4.0.1",
    "gulp-plumber": "1.2.1",
    "gulp-uglify": "3.0.2",
    "gulp.spritesmith": "^6.10.0",
    "merge-stream": "2.0.0",
    "vinyl-buffer": "1.0.1"
  }
}

EDIT: Attempted to upgrade from Node from 12.6.2 to 12.18.2 without success.

EDIT: Attempted to upgrade from Node from 12.6.2 to 14.5.0 without success.

Mick
  • 6,527
  • 4
  • 52
  • 67
  • "the advice is to downgrade gulp to version 3" - that is bad advice. `Task function must be specified` is a common error caused by migrating from gulp v3 to gulp v4 and is usually easily fixed. But you have to show your gulp v4 gulpfile.js for further help. – Mark Aug 27 '20 at 23:01

3 Answers3

18

I found a solution that does not require downgrading node or gulp, credit.

Create a file named npm-shrinkwrap.json at the same level as your package.json and fill the file with this content:

{
    "dependencies": {
        "graceful-fs": {
            "version": "4.2.2"
       }
    }
}

Now delete the node_modules folder and run npm install in the same folder and you should now be good. (Reload in the Task Runner Explorer of Visual Studio.)

Serj Sagan
  • 28,927
  • 17
  • 154
  • 183
5

I got this issue with Visual Studio 2022, when the automated Task Runner ran the gulp tasks that I set to run whenever the solution builds. Visual Studio ships with its own version of Node.js, which is used by default for the Task Runner Explorer, and I needed to configure Visual Studio to use the node version that I have installed instead.

The answer here from Joe Davis (Web tools, Microsoft) explains how to do this:

Visual Studio ships with its own version of Node.js, which is used by default for the Task Runner Explorer. If you have a different version of Node.js installed on your machine, you can use that one by changing the settings in Tools->Options->Projects and Solutions->Web Package Management. Move “$(PATH)” to the top of the list in the “Locations of external tools:” listbox.

enter image description here

Chris Halcrow
  • 28,994
  • 18
  • 176
  • 206
  • This answer is much more convenient since it doesn't require a modification / reload to your node modules and doesn't potentially interfere when you want to run your gulp tasks from the command line. – Dillie-O Oct 20 '22 at 06:59
0

The solution I found was to downgrade to NodeJs v11.15.0 and use gulp 3.9.1.

If anyone out there has a better option I'd be keen to hear it.

Mick
  • 6,527
  • 4
  • 52
  • 67