command not found: gulp

[Disclaimer] This article is just for my personal reference as I tend to quickly forget things…

So I cloned a project:

➜ Desktop git clone https://github.com/HackerThemes/theme-kit.git➜ Desktop cd theme-kit

Installed the project dependencies:

➜ theme-kit git:(master) npm i

The project suggested to run , issued the command and encountered the first issue:

➜ theme-kit git:(master) ✗ gulp watchzsh: command not found: gulp

Obviously this also won’t work:

➜ theme-kit git:(master) ✗ gulp -vzsh: command not found: gulp

Tried to install globally and failed with the following error:

➜ theme-kit git:(master) ✗ npm install gulp-cli -gnpm WARN checkPermissions Missing write access to /usr/local/lib/node_modulesnpm ERR! path /usr/local/lib/node_modulesnpm ERR! code EACCESnpm ERR! errno -13npm ERR! syscall accessnpm ERR! Error: EACCES: permission denied, access ‘/usr/local/lib/node_modules’npm ERR! { Error: EACCES: permission denied, access ‘/usr/local/lib/node_modules’npm ERR! stack: ‘Error: EACCES: permission denied, access \’/usr/local/lib/node_modules\’’,npm ERR! errno: -13,npm ERR! code: ‘EACCES’,npm ERR! syscall: ‘access’,npm ERR! path: ‘/usr/local/lib/node_modules’ }npm ERR!npm ERR! Please try running this command again as root/Administrator.npm ERR! A complete log of this run can be found in:npm ERR! /Users/sam/.npm/_logs/2019–03–02T18_41_46_883Z-debug.log

So I switched to :

➜ theme-kit git:(master) ✗ export NVM_DIR=”$HOME/.nvm”[ -s “$NVM_DIR/nvm.sh” ] && \. “$NVM_DIR/nvm.sh”➜ theme-kit git:(master) ✗ nvm — version0.33.8

And now checking gulp version worked:

➜ theme-kit git:(master) ✗ gulp -v[19:43:16] CLI version 3.9.1[19:43:16] Local version 4.0.0

However, was still throwing an error:

➜ theme-kit git:(master) ✗ gulp watch/Users/sam/Desktop/theme-kit/node_modules/node-sass/lib/binding.js:15throw new Error(errors.missingBinary());^Error: Missing binding /Users/sam/Desktop/theme-kit/node_modules/node-sass/vendor/darwin-x64–59/binding.nodeNode Sass could not find a binding for your current environment: OS X 64-bit with Node.js 9.xFound bindings for the following environments:- OS X 64-bit with Node.js 8.xThis usually happens because your environment has changed since running `npm install`.Run `npm rebuild node-sass` to download the binding for your current environment.at module.exports (/Users/sam/Desktop/theme-kit/node_modules/node-sass/lib/binding.js:15:13)at Object.<anonymous> (/Users/sam/Desktop/theme-kit/node_modules/node-sass/lib/index.js:14:35)at Module._compile (module.js:649:30)at Object.Module._extensions..js (module.js:660:10)at Module.load (module.js:561:32)at tryModuleLoad (module.js:501:12)at Function.Module._load (module.js:493:3)at Module.require (module.js:593:17)at require (internal/module.js:11:18)at Object.<anonymous> (/Users/sam/Desktop/theme-kit/node_modules/gulp-sass/index.js:162:21)

Okay, so I rebuilt the as suggested by the error output above:

➜ theme-kit git:(master) ✗ npm rebuild node-sass

So finally, I was thinking, should run, but nope, it threw another error:

➜ theme-kit git:(master) ✗ gulp watch[19:44:04] Using gulpfile ~/Desktop/theme-kit/gulpfile.js/Users/sam/.nvm/versions/node/v9.8.0/lib/node_modules/gulp/bin/gulp.js:129gulpInst.start.apply(gulpInst, toRun);^TypeError: Cannot read property ‘apply’ of undefinedat /Users/sam/.nvm/versions/node/v9.8.0/lib/node_modules/gulp/bin/gulp.js:129:20at process._tickCallback (internal/process/next_tick.js:112:11)at Function.Module.runMain (module.js:692:11)at startup (bootstrap_node.js:194:16)at bootstrap_node.js:666:3

Now I have no idea what this error is about, looks like something is wrong with or something :D

Let’s start beating around the bush, and go through all the uninstall/install trials…

Before uninstalling, checking the gulp version again:

➜ theme-kit git:(master) ✗ gulp -v[19:54:47] CLI version 3.9.1[19:54:47] Local version 4.0.0

Oki, looks like the command works.

Now, globally uninstalled :

➜  theme-kit git:(master) ✗ npm uninstall gulp -gremoved 270 packages in 1.712s

And uninstall , project dependencies:

➜ theme-kit git:(master) ✗ npm uninstall gulpnpm WARN rm not removing /Users/sam/Desktop/theme-kit/node_modules/.bin/gulp as it wasn’t installed by /Users/sam/Desktop/theme-kit/node_modules/gulpremoved 60 packages and audited 4164 packages in 4.006sfound 0 vulnerabilities➜ theme-kit git:(master) ✗ npm uninstall gulp-cliremoved 144 packages and audited 1137 packages in 3.251sfound 0 vulnerabilities

Check the version ( command shouldn’t work):

➜ theme-kit git:(master) ✗ gulp -vzsh: command not found: gulp

And guess what, I forgot to uninstall globally…

➜ theme-kit git:(master) ✗ npm install -g gulp-cli/Users/sam/.nvm/versions/node/v9.8.0/bin/gulp -> /Users/sam/.nvm/versions/node/v9.8.0/lib/node_modules/gulp-cli/bin/gulp.jsnpm ERR! path /Users/sam/.nvm/versions/node/v9.8.0/share/man/man1/gulp.1npm ERR! code EEXISTnpm ERR! Refusing to delete /Users/sam/.nvm/versions/node/v9.8.0/share/man/man1/gulp.1: ../../../lib/node_modules/gulp/gulp.1 symlink target is not controlled by npm /Users/sam/.nvm/versions/node/v9.8.0/share/man/man1npm ERR! File exists: /Users/sam/.nvm/versions/node/v9.8.0/share/man/man1/gulp.1npm ERR! Move it away, and try again.npm ERR! A complete log of this run can be found in:npm ERR! /Users/sam/.npm/_logs/2019–03–02T19_06_22_419Z-debug.log➜ theme-kit git:(master) ✗ gulp watchzsh: command not found: gulp

Now pay attention to the above npm ERR! and remove the file:

➜ theme-kit git:(master) ✗ rm /Users/sam/.nvm/versions/node/v9.8.0/share/man/man1/gulp.1

Finally, install globally:

➜ theme-kit git:(master) ✗ npm install -g gulp-cli/Users/sam/.nvm/versions/node/v9.8.0/bin/gulp -> /Users/sam/.nvm/versions/node/v9.8.0/lib/node_modules/gulp-cli/bin/gulp.js+ gulp-cli@2.0.1added 234 packages from 154 contributors in 4.738s➜ theme-kit git:(master) ✗ gulp -v[20:11:14] CLI version 2.0.1[20:11:14] Local version 4.0.0

And it works…

➜ theme-kit git:(master) ✗ gulp watch[20:11:29] Using gulpfile ~/Desktop/theme-kit/gulpfile.js[20:11:29] Starting ‘watch’…[20:11:29] Starting ‘buildCss’…[20:11:30] Finished ‘buildCss’ after 1.82 s[20:11:30] Starting ‘watcher’…

The morals of the story, I should have first checked the official documentation and initially installed the globally… :D

Everything is unknown until it’s known. Self-learner.