NPM Command Not Found - node.js

I just updated node (through the nodejs.org package installer) and now npm won't work.
npm: command not found
Any idea what's going on?

I was hung up on this too. I installed node via nvm and could not run npm or node. I had to run nvm use 0.10.10
then which node and which npm worked again.
if you have installed npm via nvm you might want to add nvm use <version> to your .bashrc file so that you'll have npm always available on any shell you open. You just need to remember to update it whenever you update npm, or use stable.

It could be a permission issue as well. If so you need to run this: sudo chown -R $USER /usr/local
This worked for me

Related

Missng NPM installer

I recently installed nodeJS and can see that it is there:
$ node -v
v14.17.0
but when I call npm it is missing:
$ npm -v
bash: /home/smoczyna/.nvm/versions/node/v14.17.0/bin/npm: No such file or directory
what is wrong here, I'm sure I had it before, how can I reinstate it now ? Or maybe better, how to reinstall whole NodeJS again instead ?
When I try this: nvm install v14.17.0 it says I already have it
Is Npm installed, What kind of OS do you use, is it linux
You could try:
ls /usr/bin | grep npm
In case of any issue with node, npm, ng commands (after upgrade or so) it is enough to delete the folder with node installation entirely and run the installer again.

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)

Angular - ng: command not found

I'm trying to learn Angular and my knowledge in terminal is beginner. After I installed Angular and then type ng new my-project. I get the response ng: command not found. I've seen other posts that had this problem and I've uninstalled and reinstalled npm and ng.
The last step I took was npm install -g #angular/cli#latest then ng new my-project.
Then I get ng: command not found.
Guess You are running on Windows
(To make #jowey's answer more straightforward).
Install Angular normally from your bash $ npm install -g #angular/cli#latest
Next is to rearrange the PATHS to
NPM
Nodejs
Angular CLI
in System Environment Variables, the picture below shows the arrangement.
I had that same problem and just solved it.
make sure you have node installed.
after running
npm i -g #angular/cli
when installation is finished, try re-opening your git bash or whatever you're using or open it in a new folder. boom. it worked for me
The error may occur if the NodeJs is installed incorrectly or not installed at all.
The proper way to fix that is to install/reinstall it the right way (check their official website for that), but if you're searching for a quick solution, you can try to install Angular CLI globally:
npm install -g #angular/cli
If it doesn't work and you are in a hurry, use sudo:
sudo npm install -g #angular/cli
Don't forget to reopen your terminal window.
For MacOS
Sometimes the ng command does not get established as a link in /usr/local/bin. I fixed the problem by adding it manually:
ln -s /usr/local/Cellar/node/10.10.0/lib/node_modules/angular-cli/bin/ng /usr/local/bin/ng
It may has not helped OP, but it solved my problem. This answer is to help others who have not tried the command mentioned in OP's question.
Just use npm install -g #angular/cli#latest. It did the trick for me.
If you have already installed #angular/cli
Then you only need to link it to npm using npm link #angular/cli
Otherwise first install angular by npm install #angular/cli and then link.
if you install npm correctly in this way:
npm install -g #angular/cli#latest
and still have that problem, it maybe because you run the command in shell and not in cmd (you need to run command in cmd), check this out and maybe it helps...
If you are working on Windows then do the following:
From this directory:
C:\Users\ [your username] \AppData\Roaming , delete NPM folder then install Angular using this command npm install -g #angular/cli
*Windows only*
The clue is to arrange the entries in the path variable right.
As the NPM wiki tells us:
Because the installer puts C:\Program Files (x86)\nodejs before C:\Users<username>\AppData\Roaming\npm on your PATH, it will always use version of npm installed with node instead of the version of npm you installed using npm -g install npm#.
So your path variable will look something like:
C:\<path-to-node-installation>;%appdata%\npm;
Now you have to possibilities:
Swap the two entries so it will look like
…;%appdata%\npm;C:\<path-to-node-installation>;…
This will load the npm version installed with npm (and not with node) and with it the installed Agnular CLI version.
If you (for whatever reason) like to use the npm version bundled with node, add the direct path to your global Angualr CLI version. After this your path variable should look like this:
…;C:\Users\<username>\AppData\Roaming\npm\node_modules\#angular\cli;C:\<path-to-node-installation>;%appdata%\npm;…
or
…;%appdata%\npm\node_modules\#angular\cli;C:\<path-to-node-installation>;%appdata%\npm;…
for the short form.
This worked for me since a while now.
Before wasting lots of time in installing and uninstalling, read this.
If you already installed angular before and found this issue, may be it is the reason that you installed angular before with running terminal as Administrator and now trying this command without administrator mode or vice versa. There is a difference in these two.
If you installed angular without administrator mode you can only use angular commands such as ng without administrator mode. Similarly,
If you installed angular with administrator mode you can use angular commands such as ng in administrator mode only.
100% working solution
1) rm -rf /usr/local/lib/node_modules
2)brew uninstall node
3)echo prefix=~/.npm-packages >> ~/.npmrc
4)brew install node
5) npm install -g #angular/cli
Finally and most importantly
6) export PATH="$HOME/.npm-packages/bin:$PATH"
Also if any editor still shown err than write
7) point over there .
100% working
Windows 10 Only
If you are using Git Bash and also you are sure that you have done all steps that are listed above, still getting an error like this, run following command:
alias ng="C:/Users/<your-username>/AppData/Roaming/npm/node_modules/#angular/cli/bin/ng"
then run ng -v
Finally, it works if you see the version of Angular-CLI
I had the same issue in Windows. I could solve it by running the ng command with npm
ng g c test
Error : C:\Users\user\AppData\Roaming\npm/node_modules/node/bin/node: line 1: This: command not found
Solution :
$ npm run ng g c test
Other solution worked for me to use Windows PowerShell or command prompt instead of bash shell
Most of the time developers install just Node.js and start working on development. This issue related angular cli dependency on your development environment.
You can fix this with command
npm install -g #angular/cli
First of all check by running
npm config get prefix
It should return some thing like (C:\Users\acer\AppData\Roaming\npm)
if it does not return it.
run npm config delete prefix
then run npm install -g #angular/cli#latest
And check by running ng --version
It has solved my problem. Hope it will help you.
**
if you have npm, install run the command
npm install -g #angular/cli
then bind your ng using this:
cd
alias ng=".npm-global/bin/ng"
Follow the Pictures for more help.
Removing NODE and using NVM instead fixed a lot of issues.
removing Node from your system
install NVM from here https://github.com/creationix/nvm
Install Node via NVM: nvm install
stable run npm install -g angular-cli
LINK
Step 1 : Delete "npm" folder from the following path
C:\Users\YourUserName\AppData\Roaming
Step 2 : Once you have the "npm" folder deleted, uninstall Node.Js.
Step 3 : Reinstall Node.JS
Step 4 : Install Angular CLI Using this command npm install -g #angular/cli#latest
Step 5: Now try : ng --version or ng -v
I had a lot of issues installing it on a mac with all the permission errors
Finally the following line solve the issue.
sudo npm i -g #angular/cli
>> npm uninstall -g angular-cli
>> npm uninstall -g #angular/cli
>> npm cache clean
Restart you machine
then >> npm install -g #angular/cli#latest
set Path : C:\Users\admin\AppData\Roaming\npm\node_modules#angular\cli
Hope you never get 'ng' not found
I tried this and everything worked by changing the npm directory.
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
npm install -g jshint
ng --version
You can install npx to use Angular CLI installed in your directory:
npm install -g npx
npx ng serve
You must know the full path of your angular installation.
For example: C:\Users\\AppData\Roaming\npm\node_modules#angular\cli\bin\ng .
Type in cmd, powershell or bash
alias ng="C:\Users\<your username>\AppData\Roaming\npm\node_modules\#angular\cli\bin\ng"
In my case
OS Version: Ubuntu 18.04.4 LTS
Node version v12.16.0
Remove ng from /usr/local/bin by using below command.
sudo rm -r ng
After that, installed ng by using command mentioned below.
sudo npm install -g #angular/cli
For Linux user
$ alias ng="/home/jones/node_modules/#angular/cli/bin/ng"
then check angular/cli version
ng --version
enter image description here
alias ng="C:/Users/<user_name>/AppData/Roaming/npm/node_modules/#angular/cli/bin/ng".. This did work..
Happy Coding :)
I guess everyone figured this out years ago but me. simple ng stopped working when I updated node. I tried all the previous suggestions in this thread to no avail but this is my solution. the command npm ng works but darn it I want just ng to work. So
I created a bat filed named ng.bat with this content
npm ng %*
either put ng.bat in a directory recognized by path or add a new path in This Computer / Properties / Advanced System Settings / Environment Variables/ System Variables / Path . For instance I added C:\Shortcuts to path.
EDIT the above answer is not THE REAL SOLUTION. What npm need is to find the npm-cli.js which is located in the npm bin directory. If a path is not set to bin then not work. I just copied npm-cli.js and put it in the npm directoy which has a path set to it.
Windows oriented:
If you're chasing an "update node/angular and I wiped my AppData
folder and now the world hates me stream of errors", then this may help.
Clear out Environment Variable settings for Node/npm/#angular/cli (They don't help)
Install Node.JS/npm from https://nodejs.org/en/ (Remember where you install it)
Confirm the location npm is [currently] running from:
npm config get prefix
Realize that is not where you just install new/fresh Node.
Update npm global pointer (which is not an environment variable)
npm config set prefix "C:\Program Files\nodejs"
Reinstall Angular
npm install -g #angular/cli#latest
Check angular install
ng --version
Hopefully this helps someone. Sorry, you'll have to reinstall any other interesting packages.
I'll add this as "yet another option" which worked for me when none of the other options worked( on windows ).
You can run the angular binary via its full path name.
node C:\Users\user\node_modules#angular\cli\bin\ng.js --version
Oddly enough, adding these paths to my env didn't work...for some reason windows opened editor to edit ng.js file instead of running it.
For me the issue was something with node. Version was very wrong somehow.
Uninstalled node from "Add or remove programs" and then re-installed it using the file from their website.

Global Node Packages Installed to Wrong Directory

I'm trying to install Hexo globally using npm. When I run
npm install -g hexo-cli
I'm informed that it was installed to /Users/myusername/.node/bin/hexo -> /Users/myusername/.node/lib/node_modules/hexo-cli/bin/hexo
The problem comes in when I run hexo init blog and the hexo command is not found.
I installed Node and npm with Homebrew, so when I run which node and which npm, the results are /usr/local/bin/node and /usr/local/bin/npm respectively.
I'm thinking that I still have leftover files and directories from when I installed Node without homebrew, but I don't want to start deleting things without fully knowing the repercussions. Would I be safe to delete all files located in the /Users/myusername/.node/ directory? I can't figure out why npm is not installing to the proper directory.
After a little digging, I found that my npm prefix variable was pointing do the wrong directory, left behind by the old Node installation. I ran npm config get prefix to see where it was pointing.
I set the new prefix value using npm config set prefix /usr/local. Homebrew is symlinked with this directory via /usr/local/bin. I uninstalled hexo-cli and reinstalled through npm, and now it works perfectly.
For NVM users
Run nvm use --delete-prefix v10.13.0 --silent replacing v10.13.0 with whatever version of node you're using.
A simple way to cope with environment variables/path problems on Windows:
Run command:
npm install -g hexo
Using node.js command prompt rather than cmd windows provided by Windows itself.

NPM Command Not Found After Installing Node

I am having a very hard time getting the npm command to work, and unfortunately my knowledge of unix isn't good enough to solve this on my own. All I've done is brew install node, and I get the following errors:
When I type npm I get zsh: command not found: npm
Looking into this issue more I found this stack overflow answer:
Command not found after npm install in zsh
Following its advice I tried adding export PATH=/usr/local/share/npm/bin:$PATH to my .zshrc file. Still get the same error when typing npm
I can confirm it is in the path echo $PATH yields /Users/nicholashaley/.rbenv/shims:/Users/nicholashaley/.rbenv/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/usr/local/heroku/bin:/usr/local/share/npm/bin:/usr/local/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/usr/local/heroku/bin:/Users/nicholashaley/.rbenv/shims:/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
I can also confirm that node has been installed node -v yields v0.12.2
Any ideas? I'm stumped
Not an answer, but maybe a solution...
Uninstall Node via brew: brew uninstall node
Then download Node from https://nodejs.org/en/download/ and install.
npm should then "just work".
I came across to this thread with the same problem but finally below is what worked for me which is without sudo
$ brew update
$ brew uninstall node
$ brew install node
$ chown -R YourUserName /usr/local/lib/node_modules/
$ brew postinstall node #This what the important step
Ok this is what worked for me:
$ brew update
$ brew uninstall node
$ brew install node
$ sudo brew postinstall node #This what the important step
In case this never got solved, this is what worked for me:
brew uninstall node
brew install node
brew doctor and see what needs to be pruned. My problem was there was a non-brew place where I had changed my install location for npm packages because I was trying to get an npm package to install for me. That was a mistake (having forgotten I initially installed node and npm through brew but now brew could no longer reach the npm install directory nor could it change or delete it). So brew prune didn't work even though the symlinks were supposedly deleted but it reminded me that I had changed the npm install location. And that brings us to:
Delete those directories
brew postinstall node
Hope it helps.
I found this article helpful with step-by-step details:
https://www.dyclassroom.com/howto-mac/how-to-install-nodejs-and-npm-on-mac-using-homebrew
Additionally, after all the steps in above article, node was working but my machine was still giving "command not found: npm". I then ran the following two commands and npm was working.
sudo chown -R myusername:myusergroup /usr/local/lib/node_modules
brew postinstall node
Anyone on the LTS release use the following command instead:
brew postinstall node#6
Issue Details in Gist and how I fixed it
1. Installed nodeJs via nvm using Git Bash
2. Installed hyper terminal & WSL
3. Installed Ubuntu (windows Store) & configured zsh shell.
4. Faced the command not found all over in the zsh shell
5. The same commands are working nicely in the bash shell
Tried sourcing the (node, nvm, npm ) paths in the .zshrc and .profile file &
modified the System & Environment Variables in Windows. None of these steps helped me to resolve the issue.
I think the issue is zsh and bash terminals treat things differently. When Installed in bash terminal the default location for the nodeJs in windows will be set to
C:\Users\Program Files\nodejs
The above one is symlinked to C:\Users\<username>\AppData\Roaming\nvm
No matter how much I tried to alias these things in zsh, only node and nvm are working with aliases. npm is failing to locate the necessary lib files.
The only solution that worked for me is Re-installing node in zsh terminal
Removed the node versions installed via nvm in Bash terminal.
Removed the nvm in windows via control Panel
Installed the nvm in the zsh shell
Installed the node latest LTS version from which npm is also installed.
Post Installing the node via nvm in Zsh I observed the following things.
Paths for the node, nvm, npm & npx have been automatically added to the $PATH variable
Node directory is not available neither in C:\Users\Program Files\nodejs
nor the C:\Users\{username}\AppData\Roaming\nvm
Instead it is configured differently at /home/<username>/.nvm/versions/node/v14.15.1/bin/node
This video really helped me in re-installing the node in ZSH: https://www.youtube.com/watch?v=kL8iGErULiw
Usually npm should be found in the same directory as that of the node executable, which can be determined by which node. Check if this directory is part of your PATH. If node was installed through a node version managers such as nodenv and nvm, check the documentation for how to add these executables to the path.
With nodenv, this can be done with:
eval "$(nodenv init -)"

Resources