175

Before clearing cache

npm cache clear

npm is working fine. After clearing cache, it is not working. The error log below suggest problem with internet connectivity but internet connection is just fine. This problem does not only happen for bower but for any modules.

Here's the output of process:

> sudo npm install -g bower Password: npm http GET
> https://registry.npmjs.org/bower npm http GET
> https://registry.npmjs.org/bower npm http GET
> https://registry.npmjs.org/bower npm ERR! network connect ETIMEDOUT
> npm ERR! network This is most likely not a problem with npm itself npm
> ERR! network and is related to network connectivity. npm ERR! network
> In most cases you are behind a proxy or have bad network settings. npm
> ERR! network npm ERR! network If you are behind a proxy, please make
> sure that the npm ERR! network 'proxy' config is set properly.  See:
> 'npm help config'
> 
> npm ERR! System Darwin 12.5.0 npm ERR! command
> "/usr/local/Cellar/node/0.10.16/bin/node" "/usr/local/bin/npm"
> "install" "-g" "bower" npm ERR! cwd /Users/username npm ERR!
> node -v v0.10.16 npm ERR! npm -v 1.3.8 npm ERR! syscall connect npm
> ERR! code ETIMEDOUT npm ERR! errno ETIMEDOUT npm ERR! npm ERR!
> Additional logging details can be found in: npm ERR!    
> /Users/username/npm-debug.log npm ERR! not ok code 0
2
  • did you figure out what was causing the issue - are you using a proxy to connect externally?
    – ali haider
    Commented Dec 31, 2013 at 16:48
  • 2
    The question here asked about "npm cache clear" but the body of the question shows output from "npm install" instead, which clearly reports an ETIMEOUT. Error, since the OP hasn't clarified in about 2 years, I think this question should be closed. Commented Aug 20, 2015 at 20:03

13 Answers 13

222

This worked for me:

npm cache clean --force 
3
  • 23
    This did not work for me on Windows 10 (no errors, just did nothing). I had to manually delete all the folders within %appdata%\npm-cache
    – plasmid87
    Commented Dec 7, 2017 at 16:18
  • Thanks, Did work for my computer with --force addition (WIN 10)
    – muratoner
    Commented Jul 18, 2019 at 6:29
  • 4
    npm WARN using --force I sure hope you know what you are doing. Be careful with the force usage, little jedi
    – KpsLok
    Commented Sep 16, 2019 at 14:40
149

It should be

npm cache clean  

See https://docs.npmjs.com/cli/cache.html

2
  • 35
    This answer may have been correct at the time, when npm was at version 1.3.8 as mentioned in the question. However, in npm 2.8.3 and npm 3.3.0, "clear" is a silent alias for "clean", so it would do the same thing. Commented Aug 20, 2015 at 19:59
  • 1
    resource not found in your shared link Commented Aug 16, 2019 at 10:36
75

"As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use

npm cache verify

instead."

6
  • 43
    "cache" and "guaranteed to be valid" do not belong in the same sentence. Commented Feb 22, 2019 at 17:03
  • 1
    @gburton, this is the npm documentation copied straight from the terminal.
    – RBZ
    Commented Feb 28, 2019 at 15:03
  • 27
    then i guess the message from NPM is wrong. Nothing is guaranteed to self heal. We don't live in a land of magic. Commented Feb 28, 2019 at 17:00
  • @RBZ please include the command that you used to generate that help statement.
    – joharr
    Commented Jun 20, 2020 at 4:42
  • 1
    @JosephHarriott You can run npm cache clean to see the exact message
    – Neil
    Commented Jun 30, 2020 at 14:01
33

try this one npm cache clean --force after that run npm cache verify

18

Try npm cache clean --force if it doesn't work then manually delete %appdata%\npm-cache folder.

and install npm install npm@latest -g

It worked for me.

visit this link

13

I try to

npm cache clean 

But npm said newer version on npm (> 5) has self healing Mechanism and every thing i need to do for checking npm is use verify

npm cache verify

npm message :

The npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. 

If you want to make sure everything is consistent, use 'npm cache verify' instead.

but for forcing npm use this:

npm cache clean --force
7

Try npm cache clean --force if it doesn't work then manually delete %appdata%\npm-cache folder.

3

Environment path may have been removed.

Check it by typing,

npm config get prefix

This must be the location where the npm binaries are found.

In windows, c:/users/username/AppData/Roaming/npm is the place where they are found.

Add this location to the environment variable. It should work fine.

(Control Panel -> Search for 'Environment Variables' and click on a button with that name -> edit Path -> add the above location)

1
  • This is highly unlikely the be the issue. Commented Apr 11, 2020 at 6:06
1

at [email protected] the command that is been supported is npm cache verify

0

I solved this issue by running cmd as an administrator. before that, I was trying to run in vs code.

run it in Power Shell or Cmd with administrative privilege. I hope that it will help.

npm install –g @angular/cli@latest
0
npm cache clean --force 

or

npm cache clean 

after that run

npm cache verify
0
npm install --cache /tmp/empty-cache
0
rm C:\Users\<User>\AppData\Local\npm-cache\
1
  • 2
    A good answer will always include an explanation why this would solve the issue, so that the OP and any future readers can learn from it.
    – Tyler2P
    Commented Oct 1, 2022 at 17:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.