50

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?

2
  • npx gulp@latest?
    – jonrsharpe
    Aug 20, 2020 at 17:31
  • @jonrsharpe unfortunately that didn't refresh the cache for npx gulp. After a couple of days I just had to clear the cache manually because it wasn't getting updated.
    – fregante
    Feb 3, 2021 at 1:08

2 Answers 2

76

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.

5
  • 3
    Why is NPX keeping around outdated versions of packages that you need to explicitly purge? Doesn't seem right
    – ChrisM
    Mar 28, 2022 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: github.com/npm/cli/issues There also doesn't seem to be many options in the official documentation either: docs.npmjs.com/cli/v8/commands/npx
    – CTS_AE
    Jun 30, 2022 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: stackoverflow.com/a/67030685/349659
    – CTS_AE
    Jun 30, 2022 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, 2022 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: github.com/npm/cli/issues/2329, github.com/npm/cli/issues/4108 Aug 1, 2022 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
1
  • 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, 2022 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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