Can no longer use npm command after trying to update - node.js

I was trying to install yeoman but it threw an error regarding self signed certificates.
I looked this up and I found out I had to upgrade node.
Upgrading node however threw this: (forgot to use sudo with it...)
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/npm'
npm ERR! error rolling back npm#1.4.4 { [Error: EACCES, unlink '/usr/local/lib/node_modules/npm']
After this I couldn't use npm anymore. It couldn't be found:
/usr/local/bin/npm: No such file or directory
Trying to reinstall with brew:
It appears you already have npm installed at /usr/local/lib/node_modules/npm
Tells me to npm uninstall but I can't use npm anymore.
The error message is more detailed but I think the part about "unlinking" is the main thing. How do I go about linking it back up and also why was such a weird error thrown?
EDIT: also ran npm config set ca "" before trying to update node.

I installed using brew
after: brew install node
sudo brew postinstall node

Found some links with similar errors and all with different solutions:
https://github.com/npm/npm/issues/4099
Error: The 'brew link' step did not complete successfully
How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
The answer for the third one helped most I think, specifically:
go to /usr/local/lib and delete any node and node_modules

sudo brew postinstall command works for me. This issue is caused if you try to update a core NPM package without using the sudo command

Related

Can't install Ember Octane on Mac; problems with NPM and NVM

I'd like to install the most recent version of Ember on my Mac with MacOS Catalina. I actually thought I had done so a few weeks ago (this machine is only three months old), but ember -v says that Ember CLI is at version 3.9 which is 13 months old.
So I entered npm install -g ember-cli in the terminal, but I get an error:
npm 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:
npm ERR! "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! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
So I did what is suggested here and tried to install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
There's some output and everything is looking finde, but when I try to verify my installation using command -v nvm, there's no output at all.
npm uninstall ember-cli gives me up to date in 0.031s.
What can I do to get Ember Octane running?
edit: I managed to install NVM using Homebrew. nvm -v says 0.35.3. But I don't find any information on how to continue from here. I still get the same error when trying to install Ember.
Your problem lies in your comment:
npm bin says /Users/<my-username>/node_modules/.bin. which ember says /usr/local/bin/ember. Now it is important to understand the PATH.
Your PATH includes multiple directories and whenever you enter a commend it will be looked up in all theese directories. Now your PATH definitly contains /usr/local/bin/ and maybe later /Users/<my-username>/node_modules/.bin. It definitly should contain borth directories. If it does not contain /Users/<my-username>/node_modules/.bin thats something you should fix immediatly.
Now however your primary problem is that you basically installed ember-cli twice in two versions with two versions of npm. At the time you've installed ember originally you didnt use nvm yet. And using npm with nvm is in some ways significantly different from using it without it.
If you're using nvm basically everything lives in your $HOME (so /Users/<username>). Also the folder where npm install -g will install binaries into, it will be /Users/<my-username>/node_modules/.bin. This is actually a good thing because this means every user can install its own things there without sudo. On the other hand if you use the global npm you will install binaries installed with npm install -g into /usr/local/bin/. This however either requires sudo or changing some permissions. We dont know what you did back then, maybe you tried it once with sudo, and since then this one version basically overwrites all other versions you may install later with nvm because /usr/local/bin/ comes in your PATH before /Users/<my-username>/node_modules/.bin.
Now what you should do is get rid of /usr/local/bin/ember first. For this you do ls -lisa /usr/local/bin/ember because this is probably a symbolic link to somewhere else. Then you check where this link leads to and remove ember-cli from there. It is probably safe to just rm -rf the packages installed there. Next you delete the symbolic link /usr/local/bin/ember itself. Then run which ember again. Not this should either either fail or point to a different path. If it points to a different path you can verify that it is the version you want (in /Users/<my-username>/node_modules/.bin). If it fails you should verify that /Users/<my-username>/node_modules/.bin is actually in your PATH and that ember exists in /Users/<my-username>/node_modules/.bin.
Besides that I want to mention that ember-cli also has some interesting detail: if you run ember-cli inside an ember project it will search for the ember-cli installed inside this project and start it. So the global installed ember-cli version actually doesnt matter that much. It is basically only relevant for ember new. However for ember new you maybe want to consider to use npx because then you will always run the current version. So you could do npx ember-cli new my-app.

Npm -v error: cannot find module 'are-we-there-yet'

I recently upgraded nodejs from v6.9.2 to V10.16.3. But after the upgrade I am not able to do npm install.
npm -v gives the following error -
Error: cannot find module 'are-we-there-yet'
I have tried uninstalling nodejs and reinstalled it. But still getting the same error.
Any solution would be really helpful.
Hm, pretty strange error, try to install it globally with npm i are-we-there-yet -g
You have broken npm by removing some of its dependencies. are-we-there-yet is a dependency of npmlog which is a dependency of npm itself, and you somehow deleted it.
So you have to reinstall the node from scratch - https://docs.npmjs.com/downloading-and-installing-node-js-and-npm

npm WARN: npm does not support Node.js v12.4.0

I've been getting the following warnings lately whenever I run any npm script:
npm WARN npm npm does not support Node.js v12.4.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11.
npm WARN npm You can find the latest version at https://nodejs.org/
It says that I should upgrade to a newer version, but v12.4 is the newest version. Even though the scripts run fine, I think there's no guarantee and something might break at any moment.
I've also tried updating npm in case there's a newer version using npm install npm -g but got the error:
npm ERR! path /usr/local/Cellar/node/12.4.0/lib/node_modules/npm
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'
npm ERR! [Error: EACCES: permission denied, access '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'] {
npm ERR! stack: 'Error: EACCES: permission denied, access ' +
npm ERR! "'/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
Then I've seen that Homebrew version of npm can't be updated using npm itself, so I tried updating through Homebrew using brew upgrade npm but got this error:
Error: npm 12.4.0 already installed
For some reason Brew mixes up nodes and npms versions.
What am I doing wrong and how can I get rid of this warning?
What worked for me:
if you try running this command "npm cache clean -f" and it doesn't work,
on your windows machine(mine is windows 10)
access the "npm" and "npm-cache" folders in this location "~\AppData\Roaming\"
delete these two folders "npm" and "npm-cache".
go to your windows search bar and search for Node, right click to open file location, run the uninstaller to uninstall NodeJs.
then visit nodejs.org and download and install node again, if you've already downloaded it, visit the folder where you downloaded it to reinstall it.
after installation, check your version of npm by typing "npm -v" on your command terminal to see the new updated version of npm installed on your machine.
now you're all set, Happy coding.
Seems like you messed up with permissions in /usr/local.
Here is how to fix that:
Fix /usr/local permissions:
sudo chown -R `id -un`:`id -gn` /usr/local
Clean npm cache and uninstall it:
npm cache clean -f
npm -g uninstall npm
Reinstall node (with npm)
brew reinstall node
Upgrade npm:
npm -g i npm
That should bring npm#6.9.2.
You should avoid using sudo while installing software with brew or npm, that could cause issues like this.
If you have nvm you may have an issue in which your node version installed at a certain version didn't match.
For example, I accidentally used: npm i -g node --force resulting in my nvm v12.21.0 to point to v16.5.0 (the latest version of node at that time directly downloadable).
To solve: I ran:
Just for good measure brew uninstall nvm
brew install nvm.
nvm uninstall 12.21
nvm install 12.21
Just for good measure I ran npm i -g npm resulting in the latest version of npm installed on that virtual node.
After installing within some repo (using npm i) you may also want to check your: ~/.npmrc.
email=myemail#company.com
registry=https://artifactory.company.com/npm/npm/
always-auth=true
user-agent=npm/6.14.11 node/v12.21.0 darwin x64
_authToken=siofjwoirgiowrgnioaenrvoianeoiio32noi23nio23nio23nio
It should look something like this: (or you might not have any of that.
Had the same issue with Debian 10 (buster) when I tried installing the npm and node.js. They were incompatible and wouldn't update. This was what I found works for me.
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
The nodejs package was installed at a different path and I manually deleted the old package (in /usr/bin/) and added a symlink to point to the new one (in /usr/local/bin).
sudo rm /usr/bin/node
sudo ln -s /usr/local/node /usr/bin/node
This is the initial printouts from running the commands. The npm version updates from 5.8.0 to 8.1.2. But the nodejs version stayed at 10.24.0 even after reboot with hash -r.
None of the answers here worked. I had to delete the npm and npm-cache folders, then reinstall npm. Details here: npm does not support Node.js v12.18.3
After step 4 posted by Styx, and if node claims installation fo a newer version but npm -v keeps showing outdated version
Code for Mac and node installed with brew:
cd /usr/local/bin/
mv npm npm-backup
mv npx npx-backup
ln -s /usr/local/Cellar/node/14.2.0/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
ln -s /usr/local/Cellar/node/14.2.0/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
npm -version
6.14.5
I hit this issue and the steps above didn't work for me. I think it can happen if you try to upgrade Node or NPM without updating the other also. At least I think that's what happened to me.
I was trying to create a new Angular project and I had a very old version on my machine. I got an error to upgrade Node, so I bumped it to the latest version. After that I got the error running any npm command.
I resolved it simply by going to:
https://nodejs.org/en/download/
Getting the latest version and installing that in a pkg file (mac). After install was complete I was able to run everything. I'm guessing it worked because the versions of each mismatched, so one wouldn't run without the other being downgraded.
I also tried the brew option but I was getting other issues. My corporate machine sometimes blocks installations in that route, so it might work for others.
For Windows, this was driving me crazy, and all of the above solutions were not working, I would still get the old version of node showing for node -v.
For me simply killing the terminal window and starting it again resolved the issue. No amount of cache clearing worked until this. I know it sounds dumb, but that's what resolved this for me in the end. Hope this helps someone else not lose hours farting around with this.
I've have this issue in npm -v package,so you have to easy step in follow of solve this problem.
npm use stable
nvm use stable
nvm cache clear
nvm install stable --default
you can closed the terminal then check the `npm --version
Looks like a permission issue. Try with sudo

Error: ENOENT: no such file or directory, scandir '.../node_modules/node-sass/vendor'

I am having an issue running my node application on a different computer than the one I usually use. After a lot of troubleshooting:
The error message I'm getting is:
Error: ENOENT: no such file or directory, scandir '.../node_modules/node-sass/vendor'
A posting that I was reading suggested that I run sudo npm install -g node-sass, which gives me the following error:
Error: EACCES: permission denied, mkdir '...nvm/versions/node/v8.9.0/lib/node_modules/node-sass/build'
I then tried to run sudo npm rebuild node-sass but I'm getting the same error message:
Error: EACCES: permission denied, mkdir '.../node_modules/node-sass/build'
I then ran sudo npm install -g node-sass --unsafe-perm=true --allow-root but it also didn't work:
ENOENT: no such file or directory, scandir '.../node_modules/node-sass/vendor'
What am I doing wrong here? Why isn't node-sass working? Why isn't sudo working properly?
Windows. Try below
node node_modules/node-sass/scripts/install.js
npm rebuild node-sass
Most probably it's not node-sass issue. This sometimes happens when you use different OS to install node-sass. As it uses some native components, the npm install must only be done one OS. Do not copy node_modules from some other place. Do a fresh install.
Have you tried deleting the node_modules directory and running npm install again?
Are you working on Windows machione where the npm install was done using a Ubuntu shell (inside windows) and now you are trying to install again from the windows command line? If so, dont. Use only one shell.
Finally if none of these help, then its possible a user permission issue. Check if you can get super user access sudo su - and then try doing a fresh npm install.
Your user does not has the rights to write in the folder you are trying. You are using 3 ... so it goes to the folder /Users on the second one you have ...nvm/versions/node/v8.9.0/lib/node_modules
This is because of a missing node-sass dependency or broken node-sass package issue.
You can resolve this by the following steps:
Install node-sass globally, if it is not installed in your system.
npm install -g node-sass
Open command prompt/terminal on the project root directory and execute the following commands.
nodejs node_modules/node-sass/scripts/install.js
npm rebuild node-sass

Can't install yeoman on Mountain Lion

I'm trying to install yeoman on Mountain Lion.
I've installed (and reinstall several times) node.js through mac package
I've installed bower and grunt successfully just in case
I've tried to make slinks of node to some bin folders just in case
And always get this error at the end when I try to install yoeman
....
npm http 304 https://registry.npmjs.org/debuglog/0.0.2
npm http 304 https://registry.npmjs.org/is
/usr/local/bin/yo -> /usr/local/lib/node_modules/yo/cli.js
> yo#1.1.0 postinstall /usr/local/lib/node_modules/yo
> node scripts/doctor.js
sh: node: command not found
npm ERR! yo#1.1.0 postinstall: `node scripts/doctor.js`
npm ERR! Exit status 127
....
I doesn't make sense that node command not found, as can run it with or without sudo.
I noticed there's another similar post :
npm install -g yo command gives -> ERR! yo#1.1.0 postinstall: `node scripts/doctor.js`
But his error is slightly different, I've tried the solution proposed even though without success.
Any advice? Thanks!
Ok! I find a solution for my case.
Let me explain:
I've installed nodejs using the .tar archive and I build it in to the
mac 10.8.5.
Then I realized there is a package for this OS, I've
uninstalled the older version and I've installed the package version.
I think I've cleaned up everything from the previous installation.
Then I've installed bower, and grunt (not necessary as I've seen later)
Then the problem is when I do sudo npm install -g yo it gives me the error shown above.
After chage lots of things and versions, I've realized that the problem was the -g option (install globally) I couldn't figure out why this option is not working for this package (yo)
I did npm install yo as root user
Finally I've moved the new node modules to the usr/local/lib/node_modules forlder , then I've created the soft links of bower, grunt-cli and cli.js to /usr/local/bin as bower, grunt and yo
Hope it could help someone for this case or maybe someone could tell me what I've did wrong at first place.
I too had this problem but like you I went to this post first:
npm install -g yo command gives -> ERR! yo#1.1.0 postinstall: `node scripts/doctor.js`
and creating a symlink worked for me, although it needed tweaking to:
sudo ln -s /usr/local/bin/node /usr/bin/node
NB prior to this I uninstalled the previous version of Node and re-installed to v0.10.24, however this didn't fix the problem with the global flag. Using the above symlink did.

Resources