14

Whenever I try to install npm-registry-client, I get the error "Error: Cannot find module 'npm-registry-client'".

I have tried to solve this with the following commands, but this did not work:

npm uninstall

npm install -g npm@latest

The full output is:

user@pc ~/devel> npm install npm-registry-client --save

module.js:340
    throw err;
          ^
Error: Cannot find module 'npm-registry-client'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/cache/caching-client.js:9:22)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

Getting the above on every npm procedure I tried so far. It appeared after updating npm

Sumurai8
  • 20,333
  • 11
  • 66
  • 100
Stephan Kristyn
  • 15,015
  • 14
  • 88
  • 147

10 Answers10

7

It seems to be a bug in npm@3.4.1. you should try upgrading from npm@3.3.6 directly to npm@next, which will bypass the buggy versions of npm. If you're currently stuck with a broken npm, and you can get back to a working npm by reinstalling Node.js.

The best way to jump over this problem is to reinstall Node using an official Node installer (not Homebrew) and use the packaged npm to upgrade straight to npm@next.

To reinstall Node.js:

rm -rf /usr/local/lib/node_modules

Using Ubuntu

curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -

sudo apt-get install -y nodejs

Using Debian, as root

curl -sL https://deb.nodesource.com/setup_5.x | bash -
apt-get install -y nodejs
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
Naveen Dahiya
  • 268
  • 1
  • 10
  • following your tip on ubuntu 15.10 I get: "/usr/bin/sudo: /usr/bin/sudo: cannot execute binary file"... this is actually two commands so 2nd sudo starts a new command! – moin moin Nov 23 '15 at 17:30
  • @mark u r right , actually i paste this stuff and didn't notice that it printed in same line, Thanks for suggestions. – Naveen Dahiya Nov 24 '15 at 10:09
  • @NaveenSingh what's your source for your statement: `seems to be a bug in npm@3.4.1`? I want to explore more about my alternatives, since 3.4.1 is currently the latest stable released. – Jesper Rønn-Jensen Nov 24 '15 at 14:36
  • 1
    @JesperRønn-Jensen it's mentioned on github issues by npm owner (othiym23). You can check this on https://github.com/npm/npm/issues/10492 in very first comment of owner – Naveen Dahiya Nov 25 '15 at 08:48
  • Info is outdated. setup_5.x will install legacy node. next time you copy paste please read before. `NOTE: Temporary info before full update of this wiki page` Downvoted. – Stephan Kristyn Dec 11 '15 at 00:15
5

I believe npm-registry-client is a separate package.

Have you tried npm install npm-registry-client --save ?

https://www.npmjs.com/package/npm-registry-client

edit: It looks like your npm is just plain broke.

Maybe these steps will help:

rm -rf ./node_modules
npm install
Drazisil
  • 3,070
  • 4
  • 33
  • 53
  • `module.js:340 throw err; ^ Error: Cannot find module 'npm-registry-client'` It's what i am getting with every other npm operation I tried so far as well. – Stephan Kristyn Nov 21 '15 at 23:37
  • 1
    This is on the npm install command? Can you edit your post to include the full error block? – Drazisil Nov 21 '15 at 23:38
  • after running the command you provided, the "ng add angular-bootstrap-md" command was ok. – JanBrus Jan 11 '19 at 13:52
2

Had same problem. I'm using Ubuntu. Steps that I've done:

  1. deleted folder /usr/lib/node_modules
  2. reinstalled nodejs using this help nodejs
  3. updated npm to latest stable using sudo npm update -g npm

Basicly you have to reinstall nodejs :( Nothing else helped. P.S. just in case: save somewhere list of packages which you need, just listing node_modules folder(ls -l /usr/lib/node_modules) and saving output. So you can reinstall them later.

mindhalt
  • 121
  • 3
  • Hi thanks for this. I am still getring the same error message even after following these steps. – Stephan Kristyn Nov 22 '15 at 22:48
  • What OS do you use? You reinstalled using tips from nodejs team(link that I gave)? What wersion of nodejs you installed? – mindhalt Nov 22 '15 at 22:51
  • Ubuntu 14.04. I have node from main repo. I tried your repo but curl gives errors, I would like to stay on offficial node release, no? – Stephan Kristyn Nov 23 '15 at 12:17
  • And you will stay on official node branch: 4.x - LTS branch, 5.x - latest stable. Ubuntus' packages are little outdated. – mindhalt Nov 24 '15 at 14:49
2

I had the same problem on Windows and found that the node uninstaller left the cache in place in AppData/Roaming.

This worked for me:

  1. Uninstall Node
  2. Remove npm and cache by hand
  3. Reinstall from the msi on the official Nodejs website
Jay
  • 452
  • 4
  • 15
1

I've solved this problem just by using npm 3.5.0

sudo npm install -g npm@3.5.0

I had this problem when I tried to install atom-editor on archlinux from AUR repository with npm 3.4.1

roadev
  • 1,002
  • 9
  • 16
1

I also encountered the same issue while working with Protractor tool. What I did was that I tried to update npm 3.4.1 to latest(this being the latest), and did it twice with below command twice:

npm install -g npm

So, something went wrong in the npm 3.4.1 and the above error kept coming.

Some issues add for this on github: https://github.com/npm/npm/issues/10492, https://github.com/npm/npm/issues/10394 and https://github.com/npm/npm/issues/2528.

Solution is to Reinstall the Nodejs by removing all the file associated with it.

Make sure you:

  1. Restart the machine after uninstalling the nodejs.
  2. Delete the following files if not already done:

    C:\Program Files (x86)\Nodejs
    C:\Program Files\Nodejs
    C:\Users\{User}\AppData\Roaming\npm (or %appdata%\npm)
    C:\Users\{User}\AppData\Roaming\npm-cache (or %appdata%\npm-cache)
    
  3. Install using the node installer.

Refer: https://stackoverflow.com/a/20711410/3619412

Community
  • 1
  • 1
Manu
  • 2,251
  • 19
  • 30
1

I had the same problem on my mac and the solution for me was uninstall my node.js and npm modules following the steps from this link:

  1. go to /usr/local/lib and delete any node and node_modules
  2. go to /usr/local/include and delete any node and node_modules directory
  3. if you installed with brew install node, then run brew uninstall node in your terminal
  4. check your Home directory for any local or lib or include folders, and delete any node or node_modules from there
  5. go to /usr/local/bin and delete any node executable

Also I did this:

  1. sudo rm /usr/local/bin/npm
  2. sudo rm /usr/local/share/man/man1/node.*
  3. sudo rm /usr/local/lib/dtrace/node.d
  4. sudo rm -rf ~/.npm
  5. sudo rm -rf ~/.node-gyp
  6. sudo rm /opt/local/bin/node
  7. sudo rm /opt/local/include/node
  8. sudo rm -rf /opt/local/lib/node_modules

Then I reinstalled a clean version of node.js. In my case is the version 5.1.0 which I downloaded from here

Jorge Casariego
  • 21,948
  • 6
  • 90
  • 97
0

Official Joyent Docs are outdated

We need to ditch tldr mentality for this one and get lastest information about setup_x.x before contintuing.

Piping curl setup_x.x to bash fails

Furthermore official Joyent Docs use curl and pipe to bash -E, which fails for me. Hence we are going to use wget.

Apt-get the lastest node package

After reading above paragraphs, you can now follow this:

sudo apt-get remove node npm nodejs -y
sudo rm -rf /usr/local/lib/node_modules  
sudo wget https://deb.nodesource.com/setup_0.12
sudo -E bash ./setup_0.12
sudo apt-get install nodejs -y
sudo npm -g install npm@latest

nodejs --version now should print latest one, e.g.

v0.12.9

Compile from Source

If nothing helps, as in my case, you want to go oldschool and compile from source:

sudo apt-get remove node npm nodejs -y
sudo rm -rf /usr/local/lib/node_modules
mkdir ~/node && cd ~/node
wget http://nodejs.org/dist/v0.12.9/node-v0.12.9.tar.gz
tar -xzvf node-v0.12.9.tar.gz
./configure && make
sudo make install
Stephan Kristyn
  • 15,015
  • 14
  • 88
  • 147
0

I had a very similar issue. Removing the entire node_modules folder and re-installing worked for me. Hope it will help you.

rm -rf node_modules
npm install
Faisal
  • 4,591
  • 3
  • 40
  • 49
0

This is what I did and worked

npm cache clean --force
npm -g install npm
npm -g install npm-registry-client
Farzad.Kamali
  • 553
  • 4
  • 10