How to clear the React Native packager


#1

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 XDE/exp, 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
  2. Run yarn or npm i 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 packager’s cache directory with rm -fr $TMPDIR/metro*
  6. Start XDE or exp
  • With exp, run exp r -c for good measure

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


Unable to resolve module....Expo fails to compile every time
Error: `fsevents` unavailable (this watcher can only be used on Darwin)
Asset Missing in published app
Am I supposed to wait on "Loading dependency graph ..."
Firebase Install Error
Uncaught Error: Application main has not been registered
Exp-cli and Exp xde Packager hanging/stalling right after "Dependency graph loaded." step
Expo XDE not working
Unable to resolve module
'regeneratorRuntime.mark' Error Related To redux-saga
Exp-cli and Exp xde Packager hanging/stalling right after "Dependency graph loaded." step
Application main has not been registered
#2

I found running

npm start -- --reset-cache

worked well.


#3

Switching from NPM to Yarn fixed it for me.


#4

Yarn user also have to clear cache?


#5

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.


#6

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


#7

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


#8

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”


#9

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"
  }
}

#10

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.


#11

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


#12

Hey @dima339,

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

Cheers,

Adam


#13

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