npm / gulp not recognized error + Primordials is not defined in task runner explorer for Sitecore Habitat project in Visual Studio 2019

npm Error:

'npm' is not recognized as an internal or external command, operable program or batch file.


Check if nodejs folder exists in c:\program files\


If not existing, install nodejs from here - https://nodejs.org/en/

Then, the nodejs folder will be created under c:\program files

Note that in the environment (system) variables, the path will also be added automatically:


Note that if nodejs folder is present in the file system but not added to the system variables list above, the npm command will not be recognized in the command prompt. So, the path needs to be added manually then.

Ensure to run npm command in a new command prompt window to check if the command is recognized.


Check gulp version with gulp -v

If gulp is not recognized across the file system, 


Run npm install -g gulp

Once the install is successful, Open a new command prompt window and check gulp -v


The fact that I'm in a totally different folder but gulp is still recognized means that gulp is installed globally.

Next, traverse to the folder where  you have the gulpfile.js and run gulp -v and I get this back -


If you now run gulp in cmd prompt and you get primordials is not defined error, refer this blog - https://navansitecorenotes.blogspot.com/2020/10/reference-error-primordials-is-not.html

In VS 2019 and within task runner explorer, you might still get the primordials is not defined error, 

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


Then, in Tools > Options, move the $PATH to top as per this answer - https://sitecore.stackexchange.com/questions/26160/issue-in-loading-gulp-tasks-in-vs-net-2019-failed-to-load


Then, reload the gulpfile.js in the task explorer window to see the tasks load fine:



Comments