Gulp: /usr/local/bin/gulp: No such file or directory - node.js

Whenever I run gulp, I get the following error:
/usr/local/bin/gulp: No such file or directory
I've followed the answers to several related questions on SO, but none have solved my issue. I've been using gulp without issue for months, but managed to screw it up somehow.
I've removed gulp and gulp-cli (using npm) both locally and globally.
After running the following:
npm install -g gulp-cli
npm install --save-dev gulp
Any command using gulp, even gulp -v returns the error mentioned above. There are no errors during the installation.
I've confirmed there is nothing at /usr/local/bin/gulp, but shouldn't reinstalling things recreate whatever files are supposed to be there?
Any help is appreciated.
EDIT:
Installing gulp globally npm install -g gulp doesn't fix anything.

Do you want to install gulp locally or globally?
Locally
npm install --save-dev gulp gulp-cli should do the trick. You can then run it using:
./node_modules/.bin/gulp
npm run gulp if you add gulp to the scripts section of package.json.
Globally
Most likely you have a $PATH issue.
Did you check where your global libraries are installed by NPM?
npm list -g
Does installing any other global library work, or is it specific to Gulp?
-- Edit --
If you are using NVM, you should add the NVM setup to your rcfile (that is, ~/.bashrc, ~/.zshrc, ~/.profile or similar). You can do so by appending these lines to your rcfile.
[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh
This will load NVM and update your PATH so that your shell is able to find gulp (or any other globally-installed program by npm or yarn).

Try npx gulp so that npm using the gulp version that is installed in your dependencies.

Related

All the npm package not installed globally can't be executed directly

Symptom:
I can't execute the npm packages directly that are not installed globally. But I can execute it by npm scripts. How to fix it?
For example:
I installed gulp under the project:
npm install gulp --save-dev
Then I try to execute it by
gulp
zsh: command not found: gulp
But if I add a npm script to package.json:
"scripts": {
"test": "mocha --require intelli-espower-loader && gulp test",
"start": "gulp"
},
Then run
npm start
It can get executed without problem.
P.S.
Same issue with the mocha package, I can't execute mocha directly but I can execute npm test without problem.
Help Wanted:
What I can do to fix that issue?
Notice:
I'm not saying that I want to execute them globally, I just want to execute them under the project.
I don't know where goes wrong, but they are executable not long ago, just don't work recently!
In addition to #Ion's answer: You might need to add the path to the environment variables. In windows OS, it would be %AppData%\npm. For packages installed locally, you should be able to run them like
.\node_modules\.bin\gulp
If you want to execute them globally install with the -g flag
npm install gulp -g
To run directly you could also do ./node_modules/.bin/gulp
That is because the package not installed globally doesn't create a reference in the root node_modules folder . If you want to specifically use the local installed version to run globally on terminal then go to you environment variables and set the path to ./node_modules/gulp/bin/gulp.js or alternatively configure your npm to use the mentioned location as the gulp and execute node_modules/.bin/gulp
You have two choices:
Install the executable modules globally:
npm install -g gulp
This is good if it's a tool you use often (for many different projects). For gulp specifically, the globally installed gulp will also check to see if the project has its own gulp installed (in node_modules) and run that version of gulp. This means that each project can have its own version of gulp. But not all tools have this feature.
Use npx:
npx gulp
Newer versions of npm ships with a command called npx which will search through your project's node_modules directory to find a module to execute. This means you don't need to install project specific tools globally. Apart form avoiding global installs of commands (which may or may not be a security issue) it also allows you to install project specific versions of tools.
If your npm installation does not have npx you can install it from npm itself:
npm install -g npx

Where to install gulp?

I'm trying to leverage from Elixer so I started to get up and running. I've installed Node and Npm. Later I also installed Gulp using sudo npm install gulp -g. But this installed Gulp in my project directory, resulting in a massive file transfer from my local host to the webserver. Is it necessary to install Gulp inside the project directory? Or is there a better way to install it somewhere else and use it for any project needed?
Sorry if this is a total beginners question but I can't seem to find an answer online. Thanks.
There is only few steps to start use it.
Install globally $ npm install --global gulp
Install directly to your project root dir $ npm install --save-dev gulp
Create gulpfile.js in root dir
Then in your new gulpfile do the follow:
var gulp = require('gulp');
gulp.task('default', function() {
// place code for your default task here
});
and after that just type gulp command in terminal to execute default task
here is documentation to help you started with gulp docs and here you can find packages to use it npmjs.com
Tip: if you on OSX use sudo to install npm/jspm/gulp etc
sudo npm install gulp -g shouldn't be installing gulp in your project directory. However, Gulp does always need to be installed locally in the project folder in order for it to work. Otherwise, you will get an error when trying to run Gulp. The -g global installion of Gulp is only needed for linking the shell to the binary $ gulp; it will dispatch to the local gulp program as soon as it is called.
Gulp, bower, ... are dependencies.
The command npm install ... will download the module to the directory named node_modules. They need to be (litterally) a part of your project. Think of it as a pure JS library (as it actually is).

Grunt installation in mac os

I want to create angular js app using bootstrap, for that I installed node.js pkg file in my mac.
Afterwards I installed yeoman ($sudo npm install --global yo). Documentation says if we install yo then we get grunt and bower automatically installed. In my case grunt and bower are not being installed.
So I decided to install it externally. I used following commands:
$sudo npm install -g bower => it works perfectly and giving me all files and packages.
$ sudo npm install -g grunt => it works perfectly but not giving me all files and packages
grunt are installed on path of usr/local/lib/node_modules/grunt
grunt folder contains files
constributing.md
licenses-mit
readme
aaveyor.yml
internal-tasks
lib
node_modules
package.json
Which files I am missing?
If I run command $ grunt --version then I got following error
-bash: /grunt: No such file or directory
How to resolve this?
You have to run:
$ npm install -g grunt-cli
The global binary command-line tool is grunt-cli, not grunt. It's a little bit confusing in the beginning, as grunt-cli provides a global binary which is callable by grunt.
So, in the end:
Install grunt locally in your application.
Install grunt-cli globally.
Then, you can run grunt from anywhere as expected :-)

Can't get Gulp to run: cannot find module 'gulp-util'

On Windows 7, I've installed gulp as explained here: http://markgoodyear.com/2014/01/getting-started-with-gulp/:
npm install gulp -g
In my app folder: npm install gulp --save-dev
I create a gulpfile.js file.
But then, when I try to run gulp, I get this error message:
module.js:340
throw err;
^
Error: cannot file module 'gulp-util'
at Function.Module._resolveFilename (module.js:338:15)
etc.
But gulp-util is present (in the local app folder) in:
node_modules
gulp
node_modules
gulp-util
Any idea what may be the cause?
UPDATE
From later versions, there is no need to manually install gulp-util.
Check the new getting started page.
If you still hit this problem try reinstalling your project's local packages:
rm -rf node_modules/
npm install
OUTDATED ANSWER
You also need to install gulp-util:
npm install gulp-util --save-dev
From gulp docs- getting started (3.5):
Install gulp and gulp-util in your project devDependencies
If you have a package.json, you can install all the current project dependencies using:
npm install
Any answer didn't help in my case.
What eventually helped was removing bower and gulp (I use both of them in my project):
npm remove -g bower
npm remove -g gulp
After that I installed them again:
npm install -g bower
npm install -g gulp
Now it works just fine.
Linux Ubuntu 18:04 user here.
I tried all the solutions on this board to date. Even though I read above in the accepted answer that "From later versions, there is no need to manually install gulp-util.", it was the thing that worked for me. (...maybe bc I'm on Ubuntu? I don't know. )
To recap, I kept getting the "cannot find module 'gulp-util'" error when just checking to see if gulp was installed by running:
gulp --version
...again, the 'gulp-util' error kept appearing...
So, I followed the npm install [package name] advice listed above, but ended up getting several other packages that needed to be installed as well. And one had a issue of already existing, and i wasn't sure how to replace it. ...I will put all the packages/install commands that I had to use here, just as reference in case someone else experiences this problem:
sudo npm install -g gulp-util
(then I got an error for 'pretty-hrtime' so I added that, and then the others as Error: Cannot find module ___ kept popping up after each gulp --version check. ...so I just kept installing each one.)
sudo npm install -g pretty-hrtime
sudo npm install -g chalk
sudo npm install -g semver --force
(without --force, on my system I got an error: "EEXIST: file already exists, symlink". --force is not recommended, but idk any other way. )
sudo npm install -g archy
sudo npm install -g liftoff
sudo npm install -g tildify
sudo npm install -g interpret
sudo npm install -g v8flags
sudo npm install -g minimist
And now gulp --version is finally showing:
CLI version 3.9.1
Local version 3.9.1
Try to install the missing module.
npm install 'module-name'
Same issue here and whatever I tried after searching around, did not work. Until I saw a remark somewhere about global or local installs. Looking in:
C:\Users\YourName\AppData\Roaming\npm\gulp
I indeed found an outdated version. So I reinstalled gulp with:
npm install gulp --global
That magically solved my problem.
You should install these as devDependencies:
- gulp-util
- gulp-load-plugins
Then, you can use them either this way:
var plugins = require('gulp-load-plugins')();
Use gulp-util as : plugins.util()
or this:
var util = require('gulp-util')
This will solve all gulp problem
sudo npm install gulp && sudo npm install --save del && sudo gulp build
None of the other answers listed here-- at least by themselves-- solved this for me.
I'm using Ubuntu 20.04 on Windows Linux Subsystem (WSL2). After reinstalling gulp globally with npm install gulp -g seemingly I needed to log out of my WSL instance and log back in again (closing and reopening my CLI was enough).
Hopefully this helps someone else.
I'm using Linux Mint 20.3. Had this error. Nothing helped.
gulp --version
node:internal/modules/cjs/loader:988
throw err;
^
Error: Cannot find module 'gulp-cli'
Found a solution after 2 hours of trying different things.
"sudo" ! simple as that.
sudo gulp --version
CLI version: 2.3.0
Local version: 3.9.1
Some gulp commands should be used with sudo to avoid errors
In most cases, deleting all the node packages and then installing them again, solve the problem.
But In my case, the node_modules folder has no write permission.
I had the same issue, although the module that it was downloading was different.
The only resolution to the problem is run the below command again:
npm install

Node Version Manager (NVM) npm installing modules to common folder

I've installed NVM for node.js using the instructions from this post:
http://www.backdrifter.com/2011/02/18/using-nvm-and-npm-to-manage-node-js/
When I switch between node versions and then use npm to install a module, all the modules are placed in the same 'node_modules' folder (~/node_modules/) instead of in the 'node_modules' directory specific to that version of node?
Any idea on how to remedy this?
Based on the comments from https://github.com/creationix/nvm/pull/97:
When installing packages with npm using the global switch -g the
package ends up in the proper directory (i.e.
.nvm/$VERSION/lib/node_modules), however node is unable to require it
since it somehow isn't searching on it's prefix.
So using npm install -g xxxxx will put the modules in the correct location for NVM but if you try to require one of them node can't find the module. I am still playing around with this and will update if I find a solution.
Update
Where does NPM put node_modules? (see https://docs.npmjs.com/files/folders)
Local install (default): puts stuff in ./node_modules of the current package root.
Global install (with -g): puts stuff in /usr/local or wherever node is installed.
Install it locally if you're going to require() it.
Install it globally if you're going to run it on the command line.
If you need both, then install it in both places, or use npm link.
So what I did was run npm init (see http://npmjs.org/doc/init.html) in my projects root dir which generated package.json. Now when I run npm install xxxxx it creates a node_modules dir in my project folder (which I add to my .gitignore). This works for modules that I require in my code.
For commands such as CoffeeScript I install with npm install -g coffee-script which puts it in the correct directory (.nvm/$VERSION/lib/node_modules). While I can't require these modules (npm link should solve this problem) I can run the commands - i.e. coffee.
I just installed express globally (-g) and was having problem when require("express"). Just like Jesse Vogt said I just reinstalled express but this time without the -g just like this: "sudo npm install express" and now is working perfectly!
For latest nvm window version 1.1.7.
Package was installed and placed into the respective nodejs version.
nvm use 16.8.0
npm install truffle
nvm use 16.7.0
npm install mysql

Resources