48

Let's say you're running this command:

npx gulp

npx will search for gulp within node_modules/.bin, and if it doesn't find it there, it will use a central cache. If it is missing, npx will install it.

How do I clear the central cache to force npx to reinstall gulp in this case?

Flimm
  • 136,138
  • 45
  • 251
  • 267

2 Answers2

73

On macOS (and likely Linux) it's ~/.npm/_npx, you can drop it with:

rm -rf ~/.npm/_npx

On Windows it should be %LocalAppData%/npm-cache/_npx


Either way, you can find npm’s cache by running npm config get cache and then finding an npx folder in there.

PitaJ
  • 12,969
  • 6
  • 36
  • 55
fregante
  • 29,050
  • 14
  • 119
  • 159
  • 3
    Why is NPX keeping around outdated versions of packages that you need to explicitly purge? Doesn't seem right – ChrisM Mar 28 '22 at 17:50
  • @ChrisM yeah it seems like `npx` should be an extension of `npm` yet it doesn't seem to have similar tooling to handle caching unfortunately. I would imagine there must be a ticket open around this, but wasn't finding anything off hand here: https://github.com/npm/cli/issues There also doesn't seem to be many options in the official documentation either: https://docs.npmjs.com/cli/v8/commands/npx – CTS_AE Jun 30 '22 at 21:50
  • 1
    If you want to know the exact directory it's running from rather than blindly clearing all of the cache you can run: `npx -p gulp which gulp` as described here: https://stackoverflow.com/a/67030685/349659 – CTS_AE Jun 30 '22 at 21:58
  • Even if I remove it it will still install the old one, so it's best to just tag the version with `@latest` I guess :\ – CTS_AE Jun 30 '22 at 22:05
  • Can confirm this works in Linux. @CTS_AE This behavior has been reported in a couple of different bugs, and both times, NPM has said it is intended behavior: https://github.com/npm/cli/issues/2329, https://github.com/npm/cli/issues/4108 – JoshuaCWebDeveloper Aug 01 '22 at 16:37
33

I needed to do this, due to an error in create-react-app saying 'We no longer support global installation of Create React App.' despite there being no global install. It was stuck in the npx cache, and I removed it like this

npx clear-npx-cache
James L
  • 16,456
  • 10
  • 53
  • 70
  • I also ran into this same issue. I was able to get around it by running `npx create-react-app@latest`. Upon inspecting the `~/.npm/_npx` I was able to see that both still exist there though. To find them I opened up the directory in VSCode via `code ~/.npm/_npx` and ran a search for `create-react-app` with `files to include` set to `package.json`. – CTS_AE Jun 30 '22 at 21:46