What is the fastest way to update node and npm? - node.js

I have searched online numerous times and I cannot seem to get it working. Please tell me if my understanding is incorrect:
To update npm to the latest version:
npm install npm#latest -g
To update node to the latest version
Go to the official website and download it. However I would like to be able to update node and npm through the command line.
Anyway, running npm install npm#latest -g gives me:
npm ERR! code EEXIST
npm ERR! path D:\nodejs\npm.cmd
npm ERR! Refusing to delete D:\nodejs\npm.cmd: is outside D:\nodejs\node_modules\npm and not a link
npm ERR! File exists: D:\nodejs\npm.cmd
npm ERR! Move it away, and try again.
Could someone please tell me the solution of this, and also provide a way to update both node and npm through the command line easily?
EDIT: Sorry forgot to say, I am using windows

Delete the node_modules directory completely.
Run npm install again.
This should help you.

Related

Is there really no straightforward way to update node and npm on windows?

Have spent far too long on this, about to give up.
I know you can go to the official website to update Node but I would like to be able to do it through the command line.
Anyway, when I do npm install npm#latest -g
I get
npm ERR! code EEXIST
npm ERR! path D:\nodejs\npm.cmd
npm ERR! Refusing to delete D:\nodejs\npm.cmd: is outside D:\nodejs\node_modules\npm and not a link
npm ERR! File exists: D:\nodejs\npm.cmd
npm ERR! Move it away, and try again.
I found another solution but did not work for me:
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install --global --production npm-windows-upgrade
npm-windows-upgrade
This works up to this far, then it asks me for which version I want to install. I select it, then I get:
You wanted to install npm 6.14.5, but the installed version is 6.13.4.
A common reason is an attempted "npm install npm" or "npm upgrade npm". As of today, the only solution is to completely uninstall and then reinstall Node.js. For a small tutorial, please see https://github.com/felixrieseberg/npm-windows-upgrade#usage.
Please consider reporting your trouble to https://aka.ms/npm-issues.
I am almost dead. Any help appreciated!
Have a look at
How can I update npm on Windows?
or
https://github.com/felixrieseberg/npm-windows-upgrade

Error installing Angular using npm due to require-from-string

How to resolve this error as I am not able to install Angular.
Please see the below exception:
C:\Users\absin\node>npm install -g #angular/cli
npm ERR! code ETARGET
npm ERR! notarget No matching version found for require-from-string#^1.1.0
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'cosmiconfig'
npm ERR! notarget
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\absin\AppData\Roaming\npm-cache\_logs\2018-01-06T19_07_00_000Z-debug.log
even after temporal solution:
npm install https://github.com/floatdrop/require-from-string/tarball/v1.1.0 --save
npm install
still getting this
as stated in the issue link:
temporal solution:
npm install https://github.com/floatdrop/require-from-string/tarball/v1.1.0 --save
npm install
UPDATE:
It appears they are working on it. The require-from-string page used to return a 404, but at least now it loads the correct page on NPM's website: https://www.npmjs.com/package/require-from-string
Still doesn't appear to be working through npm install yet.
UPDATE 2:
An official response from NPM: https://status.npmjs.org/incidents/41zfb8qpvrdj
UPDATE 3: issue seems to be resolved.
Even if https://status.npmjs.org/ says that it s all ok now,
the problem persist here
some problem with NPM registry some of the packages got deleted.
They are restoring it... it will be available shortly
Temp solution use the missing package from already running projects that or older projects.
I had the same issue. So when I used yarn it worked well and not having any problem to create new projects also.
yarn global add #angular/cli
again, when you create new app ng new newapp it will fail because at this moment npm is not able to find a package called require-from-string. But the you can run yarn to install all the packages. Yarn will ask which version of the require-from-string is needed. you can choose it.
npm is having issues. This should just work.
npm registry issue is now fixed according to https://status.npmjs.org/incidents/41zfb8qpvrdj
Solution
rm ./package-lock.json
git commit -am "Removed broken package-lock.json file."
git push heroku master

NPM install not working - one of the dependencies is missing

Whenever I try to execute npm install or npm i, I get this error:
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'json-parse-helpfulerror'
I cannot update NPM through npm install npm -g or npm i npm -g, becuase it produces the same error. My computer was very low on space, and I have a feeling it might have deleted one of NPM's dependenices. The actual npm command works though.
Is there any way to fix this?
Reinstalling npm will fix the issue.
curl -L https://www.npmjs.org/install.sh | sh
If you're on Windows and you have a broken installation, the easiest thing to do is to reinstall node from the official installer.
You can also try clearing the cache
npm cache clean

npm install no longer possible after deleting module directory

So I wanted to help out, and forked a Node-RED module to make some small contribution, but then got lost messing around with how to get Node-RED to run my fork (for testing) rather than the packaged version. Then I learned about npm's ability to install from a Github URL, which is nice, but it wouldn't work because I had already installed the module. Then I found I couldn't uninstall it either
npm uninstall original-module
npm ERR! path /home/nodered/.node-red/node_modules/original-module/package.json
npm ERR! code ELOOP
npm ERR! errno -40
npm ERR! syscall open
npm ERR! ELOOP: too many symbolic links encountered, open '/home/nodered/.node-red/node_modules/original-module/package.json'
so in frustration I deleted the module's directory, only to find myself unable to move forwards, or backwards. npm install https://github.com/me/forkedmodule fails with
npm ERR! code 128
npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b master https://github.com/me/forkedmodule.git /root/.npm/_cacache/tmp/git-clone-d31dc53b
npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-d31dc53b': Permission denied
npm ERR!
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-08-22T01_07_18_257Z-debug.log
and trying to install the original with npm install original-module fails with
npm ERR! code ENOLOCAL
npm ERR! Could not install from "node_modules/original-module" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-08-22T01_09_56_127Z-debug.log
As you've probably guessed, I'm pretty new to Node.js, Node-RED and npm, but I haven't been able to help myself, so have to ask for help! It seems nonsensical to me that npm appears to be looking for a local copy of the package.json file belonging to the package I'm trying to install?
Edit: I should add that the above commands were all run as root.
Ok, found a solution, not sure if it's the best one though!
In the "project" directory (/home/nodered/.nodered in my case) there's a package-lock.json file which lists the packages used by the project. In there I found an entry for the original-module which I removed, after which I was able to install the package "normally" with npm install original-module.
Then to solve the permission issue when installing from a GitHub URL, I found I needed to impersonate the "nodered" user with su - nodered (it's a password-less user in my case). As "nodered" npm install https://github.com/me/forkedmodule succeeded without any error. A little curious since I was trying to do this as root before, and got a permission error, but there you go. I also took the opportunity to chown -R the project's node_modules directory to nodered:nodered as I could see that was a bit of mess.
In future, I will try to remember to su - to my nodered user first, and navigating to the project root (again, /home/nodered/.node-red in my case) before running npm install anything. Hopefully that will avoid any further issues. Oh and a note to anyone else who just wants to contrib some quick changes to a module hosted on GitHub: to "pull" in changes you simply run npm install https://github.com/me/forkedmodule again - npm doesn't appear to provide any dedicated "update" method.
I had the same issue, in my case the solution was to delete the package-lock.json, delete node_modules, then reinstall npm modules.

NodeJS "npm update -g npm" fails with "Error: Refusing to delete" (Installed via package, NOT homebrew)

While trying to fix a JPG compatibility issue, I'm running into the following error when trying to update npm on my Mac OSX (Yosemite). Note that I did not install via homebrew, instead via the official package. (I'm using version 0.10.37 to counteract yet another NPM package issue).
Here are the steps I take:
brew uninstall node and brew uninstall npm to be triple-sure Node is not present on my system via Homebrew. The output is as expected, Error: No such keg: /usr/local/Cellar/node
Download the package from http://nodejs.org/dist/v0.10.37/ and install it.
node -v to verify that Node is installed.
npm update -g npm
And here's the output from that last command:
$ npm update -g npm
npm ERR! Refusing to delete: /usr/local/share/man/man3/npm-bin.3 not in /usr/local/lib/node_modules/npm
File exists: /usr/local/share/man/man3/npm-bin.3
Move it away, and try again.
npm ERR! System Darwin 14.1.0
npm ERR! command "node" "/usr/local/bin/npm" "update" "-g" "npm"
npm ERR! cwd /Users/topher
npm ERR! node -v v0.10.37
npm ERR! npm -v 1.4.28
npm ERR! path /usr/local/share/man/man3/npm-bin.3
npm ERR! code EEXIST
npm ERR! error rolling back Error: Refusing to delete: /usr/local/share/man/man3/npm-bin.3 not in /usr/local/lib/node_modules/npm
npm ERR! error rolling back at clobberFail (/usr/local/lib/node_modules/npm/lib/utils/gently-rm.js:57:12)
npm ERR! error rolling back at next (/usr/local/lib/node_modules/npm/lib/utils/gently-rm.js:43:14)
npm ERR! error rolling back at /usr/local/lib/node_modules/npm/lib/utils/gently-rm.js:52:12
npm ERR! error rolling back at Object.oncomplete (evalmachine.<anonymous>:108:15)
npm ERR! error rolling back { [Error: Refusing to delete: /usr/local/share/man/man3/npm-bin.3 not in /usr/local/lib/node_modules/npm] code: 'EEXIST', path: '/usr/local/share/man/man3/npm-bin.3' }
npm ERR! not ok code 0
When I delete the above mentioned file and try again, I get another error because the npm command no longer exists. It looks like the update partially succeeded in that the npm command was deleted:
$ npm
-bash: /usr/local/bin/npm: No such file or directory
When I search for this "Refusing to delete" error, I see tons of advice for how to fix a botched Homebrew install (plus some unnecessarily condescending instructions on how to remove the Homebrew package. But I'm not installing the package via homebrew; the advice I'm finding there doesn't seem relevant in my case.
How should I go about troubleshooting this? Anyone else know of / have this problem / can think of a quick fix?
Thanks in advance!
This isn't a complete answer, but just to follow up I found a way to work around this issue.
My ultimate need was to get node running with the package resemble installed. Resemble relies on cairo, which was installed via homebrew; it seems that this was my first mistake. Because Cairo was apparently improperly installed, a couple packages were missing; this forced me to use one workaround that triggered other errors and required other workarounds... and so forth.
When I removed the Cairo homebrew package and instead built Cairo from source (using this guide), several other errors I was having just melted away.
So the lesson I'm learning is: Don't use Homebrew for anything finnicky, or for any dependencies of anything finnicky.
I solve it by this:
rm /usr/bin/npm
/usr/lib64/node_modules/npm/bin/npm-cli.js install npm -g
npm -v # success !

Resources