repair npm global package symlinks - node.js

Recently upgraded to OSX Mavericks and had all my npm global module symlinks wiped out! Reinstalling npm got npm to work again.
Is there a way to have npm recursively go through /usr/local/lib/node_modules/
and create the symlinks in /usr/local/bin for each package? (yes, it is in my Path)
Is there a way to do this a single package at a time?
My Google-fu is failing me at the moment. I have over 40 packages and I would hate to have to reinstall all of them or manually create symlinks for all the bins!
OSX 10.9
npm 1.4.14
node 0.10.29

Run this to rebuild in place without reinstalling:
for i in "$(npm prefix -g)/lib/node_modules/"*; do
sudo npm build -g "$i"
done
But, are you sure that the symlinks are broken, and not that it simply changed your PATH environment variable or something? What does npm bin -g output?

Well this way is easy but it will re-download stuff, but it will still probably be faster than trying to script a way to repair them in place without redownloading:
npm install -g $(ls /usr/local/lib/node_modules)
If you try to manually create the symlinks, you are almost certain to miss some and/or make so mistakes, so I would not recommend that.

Related

NPM uninstall -g yo, yo still works

I'm a noob at my wits end and have already consulted a couple of friends who know (much) more than me. Sorry if these are dumb questions. Hoping you guys can help.
I think it has to do with some weird NPM pathing issues, but I can't figure them out. npm install -g generator-xxx follows through with success, but when I run Yo, no generators are listed.
Tried npm update -g npm - no dice. Npm remains out of date. This is also true of n and most (but not all? I think?) npm modules.
I tried to start from scratch, followed NPM's advice for a complete fresh start. Reinstalled node from node.js's website. Happily, node is up to date, but npm is still several released behind (2.11.3).
The most disturbing part of all of this: npm uninstall -g npm and the packages still work, which makes me think I've got a rogue npm installation rumbling around somewhere in my box, but I cannot find it.
Thanks in advance for your time and consideration!
Node loads modules from several locations by default, and is also influenced by your environment. Take a look in these locations to see if you have modules installed that you weren't aware of.
$HOME/.node_modules
$HOME/.node_libraries
<prefix>/lib/node_modules (where <prefix> is e.g. /usr or /usr/local
Any path(s) in the $NODE_PATH environment variable
./node_modules if it exists in the current directory
../node_modules if it exists
... and so on up the tree, all the way to the root of the filesystem

npm hangs on postinstall / unlock

I have a Linux server that runs some virtual Machines using KVM. Host machine is a Debian derivate with kernel 2.6.32-32(-pve).
In roughly 75% of the times I run npm install, it hangs while installing modules. I ran it in silly debug level and it always hangs at the line
npm info postinstall [module name] (older npm versions)
or
npm verb unlock done using [...] (newer npm versions)
forever.
It happens in every project on the host machine and on the virtualized systems for every node and every npm version I have tested (a lot, including the newest ones (2.7.x atm)).
It also is not deterministic. Sometimes it works, sometimes not and most of the times it hangs on a different module.
On my dev machine (which is in the same network, running OS X 10.10) it works fine.
I am not behind any kind of proxy.
What could possibly be wrong here?
EDIT: For the time being I solved this problem by checking in all my dependencies as gzipped files using https://github.com/JamieMason/shrinkpack
I was having the same issue for several hours, and couldn't work out what the problem was. I tried re-installing everything a few times, manually installing individual modules, switching from x64 to x86 versions of NodeJS, etc, and got nowhere.
In the end, I changed networks, from WiFi over ADSL2+ [~2mbps] to 4G Hotspot [~20mbps] and it worked in 30 seconds. No idea why, since it didn't seem like a network speed issue, but it solved the problem.
Hope this helps someone else, too!
I had the same problem on our Jenkins slaves based on Ubuntu, and it was solved by upgrading npm.
Default npm installed by apt-get has version 1.3.10 now, which is very old (shown by npm --version). There are at least two ways to upgrade it:
Run sudo npm install -g npm command. If you want to install a specific version you can run append it at the end of command: sudo npm install -g npm#2.1.3.
Or you could add NodeSource repositories using these instructions and run usual sudo apt-get update.
I have the same problem on Windows. I deleted my npm-cache folder and reinstalled npm. Everything started working normally after that.
The npm-cache folder can be found at
<your-drive>\Users\<your-name>\AppData\Roaming\npm-cache
Remember to turn on 'View hidden files because the AppData folder by default is hidden
You can reinstall npm by using the command,
npm i npm -g
On Windows make sure you are in a native CMD (not in VSCODE or whatever IDE). Also, try increasing the max memory limit for node:
set NODE_OPTIONS=--max_old_space_size=8096
I did the same, switched my network from WiFi to 3G and it worked.
I'm experiencing the same problem, this is the issue on Github:
https://github.com/npm/npm/issues/7862
There are some useful tips that seemed to help a few people.
For me doing $ npm install -g node-gyp (as suggested here: http://gangmax.me/blog/2013/05/13/resolve-npm-update-node-gyp-hung-problem/) fixed the problem.
I had the same problem and just run
npm cache clean
And it works!
Had this same problem in Windows. The solution was to restart after installing node and npm and then run command prompt as administrator.
In my case, a system restart did the work.
I ran npm install --verbose which suggested some lock on a file in npm-cache. And I think the system released the file (which was under use) after the system restart. I am using windows.
Try cloning the project again and then run npm install to install the packages in your terminal.
I ran into this with npm v6, and it turned out I was just being impatient. I just needed to wait a little longer and it proceeded to the next step.
npm cache clean --force
works for me :)
=> this method working with me When npm block in installation Package for IONIC installation and ReactNative and another package npm.
you can change temporary :
npm config set prefix C:\Users[username]\AppData\Roaming\npm\node_modules2
change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm\node_modules2
Run the your command to install your package .
open file explorer copy the link C:\Users[username]\AppData\Roaming\npm\node_modules
ok file yourpackage.CMD created another folder Created "node_modules2" in node_modules and contain your package folder.
copy your package file CMD to parent folder "npm"
copy your package folder to parent folder "node_modules"
now run npm config set prefix C:\Users[username]\AppData\Roaming\npm
change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm
now package working correctly with Command line

NPM appears to do nothing on Linux Mint 15

searched, and did not see this specific problem.
Trying to get a MEAN stack built on my Linux Mint machine, and bumping into a bit of an unusual issue.
Got MongoDB installed, and finally got it running correctly (none of the instructions ANYWHERE mentioned having to create the /data/db/ directory and set permissions, go figure).... it works now.
Got NodeJS installed, and it appears to work correctly.
I had been told (apparently incorrectly) that NPM installs right alongside Node, with:
sudo apt-get install nodejs
but:
$ npm
bash: /usr/bin/npm: No such file or directory
So I go ahead and install NPM separately.
$ sudo apt-get install npm
Seems to work, so far, no errors, and it looks like it is pulling down the NPM package and installing it...
$ nodejs -v
v0.10.21
$ npm -v
$
?? It simply fails to respond without any error... so I try:
$ npm install grunt -g --save-dev
$
Same completely silent failure... in fact, NOTHING I could do gets a response out of NPM.
Looked all over the web, and saw nothing similar anywhere... found out that NPM holds its cache files in ~/.npm and noticed that this folder didn't exist (kinda like the mongo issue above), so I created it, and set permissions to 7777... still nothing.
Purged and re-installed both node and npm, tried installing them both together and separately (yes, desperation)... still no love.
WTF am I doing wrong?
I would love, eventually, to have a nice development environment setup, hopefully with Cloud9 as a local IDE.... but already pulling my hair out.
=========================================================================================
OK, after a few more headaches, this is up and built now... thank you all.
Would love to mark both as answers, but it won't let me.
npm does come with node. Where is apt-get pulling it from? I install the Mac OS X packages on my Mac for development and npm does in fact come with it. I compile from source on my CentOS server and npm comes with it.
Your package provider may be providing them separately as a (in)convenience to you.
As for why your npm command does not work after installation, I can't say for sure, but I am suspicious of your use of --save-dev and -g together.
-g means to install globally, which means 2 things:
It will be installed outside of your npm package's structure into a system location like /usr/bin or /usr/local/bin
It requires root access to install. Did you use sudo to run it with root access?
Both of those requirements conflict with --save-dev which records the package as a dependency in your package.json file so that future npm install commands will install that package within the project space.
That said, I happen to know a lot about grunt. It has 2 parts, a globally installed tool and the package-specific tool. The correct way to install it is:
$ [sudo] npm install -g grunt-cli
$ npm install grunt --save-dev
This will install the grunt-cli package into a system location guaranteed to be in the $PATH, which turns around and looks for a package-specific grunt installed which is not system-wide.
When installing nodejs with npm, this one-liner worked for me.
sudo apt-get install nodejs nodejs-dev npm
I don't believe npm comes with the nodejs installation in the apt repo. Try to install npm separately using the following tutorial http://www.giantflyingsaucer.com/blog/?p=1688 'To install NPM ....'
====== Edit ====
node and npm IS separate. Follow the official wiki and everything should be fine

npm comes with node now. What does this mean?

Node noob here.
I had previously installed both npm and node separately.
Apparently, npm comes with node now. (link)
To my newbie mind, this means my previous dual installation is old and ugly. 1 binary > 2 binaries. So i uninstalled both.
Then I installed the latest node following the procedure. (i am running eOS)
Terminal
user#box:-$ which node
/usr/bin/node
user#box:-$ node -v
v0.10.22
user#box:-$ which npm
user#box:-$ npm -v
bash: /usr/bin/npm: No such file or directory
I can always run:
curl https://npmjs.org/install.sh | sh
but that seems to indicate that npm is actually NOT included in node.
When they say they are included do they just mean the code is in the same repo, but the binaries are still different?
Final question I have /usr/bin/node as well as /usr/bin/nodejs
can i delete one of these? im not sure when/where i picked up a second copy.
Yes, the nodejs package includes both node and npm executables. The code for each has its own repo, but when packaged both are included.
npm source: https://github.com/isaacs/npm
node source: https://github.com/joyent/node
When you install that .deb file from the PPA, you should get both /usr/bin/nodejs and /usr/bin/npm and 2 symlinks at /usr/bin/node (which points to) /etc/alternatives/node (which points to /usr/bin/nodejs).
If any of this isn't true, your install didn't fully succeed, most likely due to conflicting files you left around from your manual install. I would suggest uninstalling the .deb then making sure there are no stale files left from your manual install and then installing again.
Only node.js packages comes with npm. so if you are installing using an .msi, .exe, .dmg .pkg, .deb or using a package installer like apt-get, yum or brew, then you'll have both node and npm.
However,npm is not part of the node core. if you are installing node and using a method where you are using ./configure or make install || make link, then npm will not be installed, and will need to be compiled using the same type of installation, and node will have to be placed on your path.
If you used git, or unzipped node and you can see a configure script, then you will also need to acquire npm.
I've had issues (mostly on Mac) with npm ending up in directories that aren't in the terminal PATH. If you can figure out where npm is located, you can just add it to your path with something like:
export PATH=$PATH:/path/to/npm
I think (I'm not on a mac so I can't check at the moment) that it sometimes gets put in /usr/local/share/. But at any rate, the problem is likely NOT that npm isn't installed, but that it's installed somewhere you're not expecting.
Few months ago i had started learning the react so all this stuff i needed to install my laptop that had the ubuntu operating system.
What i did -- First i installed the node and without knowing that it came up with the npm package. I installed the npm package again.. but there was no conflict at all.
But after exploring all these things that nodejs have npm package. So i uninstalled the npm package due to concern about memory usage..
And Now everything is working fine....

lock global npm packages

Is it possible to lock global packages to a specific version? For example if I do:
$ npm install -g some-awesome-package#1.7.0
if some-awesome-package#1.7.1 exists, can I prevent npm from ever updating this specific package?
The answer appears to be no. I opened this issue but it got closed. It's hard to imagine that I'm the only person with this use case though.
There may be a way to do this through the npm CLI, but I can't find it. There doesn't seem to be a npm shrinkwrap for global packages, either.
I thought it might be possible using npm link (which creates a symlink from a local package to the global folder), but running npm install -g somepackage#foo after npm link, does overwrite the previously installed global package.
One (very hacky) way to force npm to fail when it tries to overwrite your globally installed package is to remove write permissions for the folder (for the user account that runs npm) with something like this chmod -w /usr/local/lib/node_modules/<some package>.
Once you do that, then npm can't install/update that global package because it doesn't have write access. I can't say I recommend going down that road, though.

Resources