How to clear react-native cache?

后端 未结 13 2147
傲寒
傲寒 2020-12-02 19:49

In react-native development, there are multiple caches used when the app is built:

  1. React-native packager cache
  2. Emulator cache
  3. Java side cache
13条回答
  •  自闭症患者
    2020-12-02 20:44

    Here's a great discussion on GitHub which helped me a lot. Clearing the Cache of your React Native Project by Jarret Moses

    There are solutions for 4 different instances.

    1. RN <0.50 -
      watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache

    2. RN >=0.50 - watchman watch-del-all && rm -rf $TMPDIR/react-native-packager-cache-* && rm -rf $TMPDIR/metro-bundler-cache-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache

    3. NPM >=5 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache verify && npm install && npm start -- --reset-cache
    4. Windows - del %appdata%\Temp\react-native-* & cd android & gradlew clean & cd .. & del node_modules/ & npm cache clean --force & npm install & npm start -- --reset-cache

    The solution is similar to Vikram Biwal's Answer.

    And there is a discussion below in the given link, so even if the above 4 cases don't work for you, you can scroll through and find a possible solution.

提交回复
热议问题