How to clear the Expo and React Native packager caches (Metro, Watchman, Haste)

This guidance is from:

When you’re unable to load a bundle, look at the packager logs or the error message displayed in the Expo client to see if it’s related to the packager. If so, you should try clearing the packager’s state to reduce the chance the bug is related to a stale cache or corrupt process.

These instructions are for macOS and Linux, but the general ideas apply to Windows as well.

  1. Stop Expo CLI (expo), which should also stop the packager. Check your list of running processes to ensure these processes are not running.
  2. Delete node_modules in your project
  • If your project depends on other local projects (e.g. has a file: URI in its dependencies), clear those local project’s node_modules directories too for good measure even though it’s probably unnecessary.
  1. Clear your Yarn or npm cache, depending on which you’re using, with yarn cache clean or npm cache clean --force
  2. Run yarn or npm install to install your dependencies again
  3. Run watchman watch-del-all to clear Watchman’s state
  4. Kill the watchman daemon process
  5. Delete the Metro cache directory with rm -fr $TMPDIR/metro-cache
  6. Delete the Haste map cache, which is used to track scanned files, with rm $TMPDIR/haste-map-*
  7. Start Expo CLI with expo start --clear; the --clear option instructs the bundlers (e.g., Webpack, Metro) to clear their caches

And just to be sure, force quit the Expo client on your phone or simulator and re-open it.

18 Likes

I found running

npm start -- --reset-cache

worked well.

2 Likes

Switching from NPM to Yarn fixed it for me.

4 Likes

Yarn user also have to clear cache?

1 Like

When I get this error, if I navigate into the node_modules folder and then the folder of the package I’m trying to install, it’s usually empty except for a package.json file…

In this case, npm was choking on an react-navgation, which doesn’t have a release that isn’t beta, so it was installing v0.0.0 with just package.json in it.

installing a specific version, npm install --save react-navigation@1.0.0-beta.11 and then cleaning the npm cache solved it for me.

Hi,

I am running into the same issue. When I follow the steps I found out I do not have ‘watchman’. what should I do in this case?

I am using Expo XDE environment

If you don’t have Watchman installed then you can skip that step.

Hi,

Thanks for your prompt reply! If it still does not fix the issue, what should I do next? In the XDE says “restarted Watchman”

I am getting

18:03:38 [exp] Warning: Expo version in package.json does not match sdkVersion in manifest.
18:03:38 [exp] Warning: Installed version 1.0.0-beta.27 of 'react-navigation' does not satisfy required version 1.5.8

The first warning is incorrect, unless the ^ carrot described in the docs is causing a string comparison mismatch https://blog.expo.io/expo-sdk-v26-0-0-is-now-available-2be6d9805b31 (^26.0.0 === 26.0.0), but in the node_modules/expo/package.json it does say it is version 26.0.0.

The second warning is weirder, browsing my node_modules/react-navigation/package.json I see v1.5.8 is the actual installed version. Not sure where or which cache its getting 1.0.0-beta.27 from, as I followed all steps described in OP.

Note I’m on a windows machine, so I had to deleted all the metro bundler cache items in %appdata%\Temp\ but can’t be sure if I missed any without emptying that whole folder.

Anyway everything works and my yarn.lock (yarn 1.5.1) says

react-navigation@1.5.8:
  version "1.5.8"
  resolved "https://registry.yarnpkg.com/react-navigation/-/react-navigation-1.5.8.tgz#f04bec1a39af8cfcf651337d351e8d0a144f1b6d"
  dependencies:
    clamp "^1.0.1"
    hoist-non-react-statics "^2.2.0"
    path-to-regexp "^1.7.0"
    prop-types "^15.5.10"
    react-lifecycles-compat "^1.0.2"
    react-native-drawer-layout-polyfill "^1.3.2"
    react-native-safe-area-view "^0.7.0"
    react-native-tab-view "github:react-navigation/react-native-tab-view"

I did not have this issue until upgrading to Expo 26.

Here’s my full package.json

{
  "name": "journal",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "react-native-scripts": "1.9.0",
    "jest-expo": "^26.0.0",
    "react-test-renderer": "16.0.0"
  },
  "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
  "scripts": {
    "start": "react-native-scripts start",    
    "exp:start:lan": "exp start --lan",
    "exp:android": "exp android",
    "eject": "react-native-scripts eject",
    "android": "react-native-scripts android",
    "ios": "react-native-scripts ios",
    "test": "node node_modules/jest/bin/jest.js --watch"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/vector-icons": "^6.2.2",
    "apollo-cache-inmemory": "^1.1.5",
    "apollo-client": "^2.2.0",
    "apollo-link-context": "^1.0.3",
    "apollo-link-http": "^1.3.2",
    "expo": "^26.0.0",
    "graphql": "^0.12.3",
    "graphql-tag": "^2.6.1",
    "native-base": "^2.3.7",
    "react": "16.3.0-alpha.1",
    "react-apollo": "^2.0.4",
    "react-native": "https://github.com/expo/react-native/archive/sdk-26.0.0.tar.gz",
    "react-navigation": "1.5.8"
  }
}

After changing my package.json to exact semver, seems the metro bundler cache is still throwing incorrect warnings (Expo v26.0.0, Exp CLI v53.0.2) . I’ve opened an issue here: https://github.com/expo/expo/issues/1656

UPDATE WITH SOLUTION: assuming you are using yarn/switched to yarn recently, ensure removal of the old, leftover package-lock.json in the root of your project. Exp start / metro-bundler seems to compare package.json semver with package-lock.json, even when using yarn & having an up-to-date yarn.lock.

1 Like

How to clear the cache on Windows? Command watchman does not work …

Hey @dima339,

I’ve never developed on Windows, but this may help: https://gist.github.com/jarretmoses/c2e4786fd342b3444f3bc6beff32098d

Cheers,

Adam

1 Like

thank you ,friend.
Also helped clear the cache on the phone in the app EXPO.

You helped me, thanks

For windows, delete the folder template cache from C:\Users\accountName.expo directory

1 Like

What about linux?

The equivalent would be ~/.expo/template-cache

I ran into some sort of caching problem yesterday. I created a new app using expo init, but when I tried to load it in the Expo app on my Android phone, I got an error saying that it could not find the splash screen asset from the last app I was working on. Then immediately after the error, the old app loaded up in the Expo app! expo start -c did not help.

I initially thought it was something on my laptop that was still running or caching something. I checked that I wasn’t somehow still running expo start in the other app’s directory. I looked for and killed any processes that might be related to Expo (looking for anything mentioning expo/watchman/haste/metro). I found a watchman process that I killed and an adb process that I killed just in case.
I then went looking for cached stuff to remove and removed anything in $TMPDIR related to expo/watchman/haste/metro. Still no luck.

Several times afted killing something or removing something I made sure to kill the app on my phone before trying again. This did not help.

I tried clearing npm/yarn caches, although that didn’t seem likely to help. It did not.

Then I found out about watchman watch-del-all. Unfortunately that did not help either.

I decided to see what would happen if I opened the web version of the app. That worked! Of course that uses webpack instead of metro so I was still thinking there was something wrong on my laptop.

I was starting to think I might have to reboot my laptop, but then I thought of clearing the app’s cache/data on my phone.

Finally that solved the problem!

So just restarting the app should normally work, if all else fails, clear the app’s cache and/or data. Then open it again, log in, and hopefully that will fix it.

The above was with expo-cli version 3.9.1 and Expo app version 2.13.1.

You just saved me! after a day struggling, thanks :blue_heart:

Thank you for this! I am working on a React-360 project, and this was a real life-saver. I registered for expo.io just so I could like your post and to say “Thank You”.