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

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

Related

npm ERR! cb.apply is not a function

I am getting this error
npm ERR! cb.apply is not a function
in Linux while doing npm install although my npm version is 6.9.0. My node version is v12.18.3. How to resolve this issue?
Would be helpful if you shared if it's Windows or Linux, but the error seems to occur on Windows. Possible solution:
1. Go to C:\Users(your username)\AppData\Roaming
2. Delete the npm folder (possibly back it up) and if there is one npm cache folder.
3. Run `npm cache clear --force` (--force is now required to clean cache)
After that, npm install should work fine.
Mac/Macbook users
Since this question is fairly active and a top google result for this issue (I know the OP is using Linux), here is how to fix it on a Mac.
On a Mac you do not have the AppData\Roaming folder, so simply run npm root -g and then navigate to the hidden directory and delete the node_modules there. If using nvm you'll need to rerun nvm use x.x.x (where x.x.x is your version).
Solution for Windows:
In my case I didn't want to delete all the npm directory inside C:/users/me/AppData/Roaming/ because I had many global modules that already existed and installed.
What worked was inspired by #user14360499's answer:
go inside C:\Users\me\AppData\Roaming\npm\node_modules
delete the npm dir
npm install my project, and keep working as usually
Solution for ubuntu 18.04:
sudo apt-get remove nodejs
sudo apt-get remove npm
sudo rm /usr/local/bin/node
sudo rm /usr/local/bin/npm
sudo apt-get install nodejs
sudo apt-get install npm
Then try node and npm version:
node -v
npm -v
If it says there is no such node/npm after you already install, then:
sudo ln -s /usr/bin/node /usr/local/bin/node
sudo ln -s /usr/bin/npm /usr/local/bin/npm
Try this if the command works:
npm -v
node -v
In case when you want to update npm/node stable version:
sudo npm install n -g
sudo n stable
I had the same issue with Nodist. After changing my Node version, my npm version was actually incompatible with it. So if you're using Nodist, make sure to run nodist npm {scope} match after switching Node versions, where scope is either global, local or env.
For me, on Centos 7, it was about removing graceful-ts used locally by npx. First, I've had to open log file which was mentioned in the error message:
npm ERR! cb.apply is not a function
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-04-04T07_45_27_182Z-debug.log
In that log file there was this path:
verbose stack at /usr/local/lib/node_modules/npx/node_modules/npm/node_modules/graceful-fs/polyfills.js:287:18
So I removed whole graceful-fs directory and ran npx again. Everything worked.
rm -fR /usr/local/lib/node_modules/npx/node_modules/npm/node_modules/graceful-fs
Had the same error (macOS Big Sur) when i tried to use npx.
How i fixed it (using nvm)
when i run:
nvm ls
nvm ls output
Fix:
nvm alias default node
nvm install 'lts/*'
nvm install output
Ciao, this problem could be connected to graceful-fs package. You could try to reinstall it:
npm install graceful-fs --save-dev
In my case it was indeed the graceful-fs package. Running
npm i -g --force graceful-fs
fixed the issue. I also ran nodist npm {scope} match before but I'm unsure if it was neccessary.
Solution for Ubuntu 18.04=>
Visit 'usr/lib/node_modules'.
Delete 'n', 'npm','npm-clean','npm-install-peers'. That means delete all the node & npm related folders.
Install the npm again.
I have tried a lot of solutions from different posts and google pages and nothing worked for me.
I ended up cleaning all traces of node, nodejs, and npm. May need some manual force remove after the purge call. And then installed using nvm.
https://linuxize.com/post/how-to-install-node-js-on-ubuntu-20-04/#installing-nodejs-and-npm-using-nvm
And it resolved the issue for me. It got the nodejs v 15.4.0 and the compatible version of npm 7.0.15 ( before using apt-get it was installing npm 6.9.0)
On macOS BigSur, I had this problem when executing:
npx install-peerdeps --dev eslint-config-airbnb
To fix, I ran
brew update
after which I was prompted to run
brew upgrade
Running the two commands fixed the issue.
I had this problem while trying to run npx.
I found that nvm had been removed from the PATH.
I added it back to my .zshrc file and it worked.
In my case (Mac) it was because I had npx installed alongside n (alternative to nvm).
$ which npx
/usr/local/bin/npx
I removed this exectutable and now:
$ which npx
/Users/MY_USER/n/bin/npx
and it works now.
I was getting this error when running npx sb init. For some reason, the command worked localy but not in CI. I tried most of the solutions from here. But only the following worked.
I replaced npx sb init with yarn global add #storybook/cli && yarn exec sb init as suggested here: https://github.com/yarnpkg/yarn/issues/3937#issuecomment-751289438
(NVM, Node.js 14, Yarn 1)
if you are also getting this error:
1 warn npm npm does not support Node.js v16.2.0
that means that your npm version is not correct.
reinstall npm, try again.
It works for me.
Feb 2021 fix:
npm install
And then commit the changes to package-lock.json. That should update all your dependencies, thus fixing this issue.
More info: https://help.heroku.com/ZV7S7D6T/why-is-my-node-build-is-suddenly-displaying-npm-err-cb-apply-is-not-a-function (this happened to me on heroku)
For linux users:
uninstall NPM, to do it go to /usr/local/lib/node_modules and do:
sudo rm -r n npm npx
Once uninstalled, re-instal it:
npm install
Even after doing this, in a specific project when trying to install a specific npm package, you may get the following error:
bash: /usr/local/bin/npm: No such file or directory
If so, in the terminal just run:
hash -r
Now you can retry installation of your wanted npm package.
For me , the solution was to delete the node modules and bower components folder of the project.
for the mac OS remove the node version and reinstalling was work for me. I used n npm version manager.
On windows, using nvm, i just installed a newer nodejs version (before 14.17.0, now 14.18.2)
So many solutions just made me even more puzzled. I downloaded and installed the newest LTS NodeJS and it worked just fine.
https://nodejs.org/en/
I'm on a Mac, and had exactly the same issue. Deleting the node modules seemed a little overkill for me, so I ran npm update and it solved the issue! Please note I did not yet have any package.json or any modules on the repo I was working in.
Windows 10:
When calling npx create-react-app my-app, i got following error:
npm ERR! cb.apply is not a function
To fix it, i did the following:
Go to the folder you want to create the app in.
npm install create-react-app --save-dev
npx create-react-app my-app
The problem has occured when the node and npm packages are not latest.
For me the problem is resolved when I completely removed npm and node, and made a clean installation.
I am using ubuntu 22 lts
to remove node and npm completely I have followed this answer
Had this issue when creating a new react app using create-react-app.
I was using nvm, so I just updated it to the latest LTS version:
nvm install --lts
then switched to the newly installed lts version:
nvm use --lts
closed and reopened the terminal, reran create-react-app and the error was fixed!
Solution for ubuntu =>
Completely remove nodejs and npm from your system.
sudo apt-get remove nodejs
sudo apt-get remove npm
Install node from this reference (https://computingforgeeks.com/install-node-js-14-on-ubuntu-debian-linux/) - This will inturn install latest npm .
Had the same error was simply in the wrong folder -.- (not a typescript project)

Gulp: /usr/local/bin/gulp: No such file or directory

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.

Installed npm packages dont work [duplicate]

I tried to install twitter bower on my Mac, and I used
npm install bower -g
Then I tried bower --help, and the output was bower command not found. Why is that?
Just like in this question (npm global path prefix) all you need is to set proper npm prefix.
UNIX:
$ npm config set prefix /usr/local
$ npm install -g bower
$ which bower
>> /usr/local/bin/bower
Windows ans NVM:
$ npm config set prefix /c/Users/xxxxxxx/AppData/Roaming/nvm/v8.9.2
$ npm install -g bower
Then bower should be located just in your $PATH.
I am almost sure you are not actually getting it installed correctly. Since you are trying to install it globally, you will need to run it with sudo:
sudo npm install -g bower
Alternatively, you can use npx which comes along with the npm > 5.6.
npx bower install
This turned out to NOT be a bower problem, though it showed up for me with bower.
It seems to be a node-which problem.
If a file is in the path, but has the setuid/setgid bit set, which will not find it.
Here is a files with the s bit set: (unix 'which' will find it with no problems).
ls -al /usr/local/bin
-rwxrwsr-- 110 root nmt 5535636 Jul 17 2012 git
Here is a node-which attempt:
> which.sync('git')
Error: not found: git
I change the permissions (chomd 755 git).
Now node-which can find it.
> which.sync('git')
'/usr/local/bin/git'
Hope this helps.
I am using node version manager. I was getting this error message because I had switched to a different version of node. When I switched back to the version of node where I installed bower, this error went away. In my case, the command was nvm use stable

npm still installing packages to '/usr/local/Cellar/node/...' even though I've uninstalled Homebrew's version of node

It's been a long night. Originally I had node installed from the package on https://nodejs.org/. However, for some reason (I can't remember why now!), I decided to try uninstalling this and then installing node through Homebrew.
Everything seemed to go fine. I then ran the following:
$ npm install grunt -g
$ npm install grunt-cli -g
But then when I tried running any of my Grunt tasks I get the following:
$ cd /some/project/that/used/grunt
$ grunt
-bash: grunt: command not found
I tried uninstalling the Homebrew version of node:
$ brew uninstall node
I then installed the nodejs.org package again. However when I try to install an npm package it ends up back in the /usr/local/Cellar/node/... directory:
$ sudo npm install grunt -g
Password:
grunt#0.4.5 /usr/local/Cellar/node/0.12.2_1/libexec/npm/lib/node_modules/grunt
├── which#1.0.9
...
I also found https://github.com/Homebrew/homebrew/issues/22408 and tried the symlink:
$ ln -sf /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
No luck. How can I get npm to stop installing packages in /usr/local/Cellar/... and get Grunt running again? Thank you!
This seemed to work. I found the following in /usr/local/lib/node_modules/npm/npmrc:
prefix=/usr/local/Cellar/node/0.12.2_1/libexec/npm
I removed this line and re-installed the grunt and grunt-cli packages. It works now.

bower command not found

I tried to install twitter bower on my Mac, and I used
npm install bower -g
Then I tried bower --help, and the output was bower command not found. Why is that?
Just like in this question (npm global path prefix) all you need is to set proper npm prefix.
UNIX:
$ npm config set prefix /usr/local
$ npm install -g bower
$ which bower
>> /usr/local/bin/bower
Windows ans NVM:
$ npm config set prefix /c/Users/xxxxxxx/AppData/Roaming/nvm/v8.9.2
$ npm install -g bower
Then bower should be located just in your $PATH.
I am almost sure you are not actually getting it installed correctly. Since you are trying to install it globally, you will need to run it with sudo:
sudo npm install -g bower
Alternatively, you can use npx which comes along with the npm > 5.6.
npx bower install
This turned out to NOT be a bower problem, though it showed up for me with bower.
It seems to be a node-which problem.
If a file is in the path, but has the setuid/setgid bit set, which will not find it.
Here is a files with the s bit set: (unix 'which' will find it with no problems).
ls -al /usr/local/bin
-rwxrwsr-- 110 root nmt 5535636 Jul 17 2012 git
Here is a node-which attempt:
> which.sync('git')
Error: not found: git
I change the permissions (chomd 755 git).
Now node-which can find it.
> which.sync('git')
'/usr/local/bin/git'
Hope this helps.
I am using node version manager. I was getting this error message because I had switched to a different version of node. When I switched back to the version of node where I installed bower, this error went away. In my case, the command was nvm use stable

Resources