-bash: <npm-package>:command not found [Mac] - node.js

I've been installing a lot of packages from Github via NPM. For example, Moneda.
When I try to run the package, I get
-bash: moneda: command not found
This happens for every package I install with NPM from Github.
I've tried resetting bash completely.
This is what I get when typing echo $PATH:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I've tried uninstalling brew, npm, node and reinstalling them all, still not working. I don't know how to fix this.

The bigger question is : where does npm install its packages? If the configuration directory of npm is ~/.npm-global, then you have to update your PATH
export PATH=~/.npm-global/bin:$PATH
More information can be found here

Related

-bash: npm: command not found after using Node LTS installation package

I have tried installing Node (and therefore also npm) using the current LTS installer package from their website, which all seemed to go ok. However, when I try using the npm command I get -bash: npm: command not found
As per answers elsewhere on this site I tried the installer again but fared no better. /usr/local/bin is in my $PATH and there is an npm listed in that directory which links to a file called npm-cli.js elsewhere, but when I which npm nothing comes up.
Do I have to add something else to my $PATH?

npm 'command not found' no matter what I try

On MacOS:
I'm unable to execute any npm package command. Every time I try, I see command not found. Like so:
-bash: live-server: command not found
I've installed node.js directly from the website.
https://nodejs.org/en/download/
I've installed live-server globally, and locally. It appears to work. When I try the command, it fails.
I've removed node.js and npm, re-installed and still fail to execute a command. I'm quite stumped. I've reviewed similar posts, implemented the suggested solutions and still can't manage to execute any npm command.
Several of the posts I've reviewed:
sudo: npm: command not found
NPM Command Not Found After Installing Node
What should I do next?
Are you using Windows?
Did you check if NPM is in Path on "Environments variable"
My bash_profile file had the wrong data saved. Correcting the file solved the problem.

Can install but can't run npm packages

I'm having trouble with my node.js/npm setup,
I freshly installed it via the website and it worked fine.
It told me to make sure /usr/local/bin/npm has to be in my path and when I run
echo $PATH it is in there, so it should be fine.
I can now install packages (tested with npm i webpack -save-dev) the installation works as expected, without any errors.
But when i run webpack all It is giving back is command not found has anyone experienced
something like this before?
I believe what you are looking for is a global package install.
Try using
npm i -g webpack
You can get help on install with
npm help i
Did you install node v8/npm v5?
In that case, it seems there's an open big-bug ticket on the npm repository.

NPM not working. Cannot find module 'strip ansi'

I just downloaded node but npm is not working. whenever I use a npm comman I get Error: cannot find module 'strip-ansi'.
For what it's worth, this ended up happening to me, using nvm on mac. npm cache clean didn't work. I ended up reinstalling via nvm:
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
$ nvm install node
I was stuck on this problem too. Finally, I solved the issue by adding value '.js', '.ts' to resolve.extensions in my webpack.config.js. If you are using webpack too, this may help.
just reinstall strip using npm install strip --save this kind of error occurs because some file may be corrupt in strip library if this will not work you can try also npm install you will solve this error.
I hit this same issue. I tried to update npm after a fresh Node.js install, but cancelled in the middle because it appeared stuck. Reinstalling Node.js didn't help.
I resolved the issue by deleting the temporary npm files in my AppData folder (for me on Windows, I found it in c:\Users\Me\AppData\Roaming\npm). Then I was able to run npm normally again.
Hope that helps!
It solved for me by going to the NPM install folder at /usr/local/lib/node_modules/npm and running the yarn command. After running it successfully, NPM started working normally.
I had the same issue with my next js application. What i did was uninstall strip-ansi(npm uninstall strip-ansi) and then reinstall (npm install strip-ansi)
Clear your temporary paths of npm and this is solution.
if you're using linux:
go to $ cd /tmp/
search by npm-* folders
and remove all.
Solved by doing npm cache clean and then npm install

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