Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Task Runner Explorer - ReferenceError: primordials is not defined

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.

like image 405
Mick Avatar asked Dec 05 '22 08:12

Mick


1 Answers

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.)

like image 154
Serj Sagan Avatar answered Feb 20 '23 14:02

Serj Sagan