How to clear react-native cache?

后端 未结 13 2110
傲寒
傲寒 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:37

    try this

    react-native start --reset-cache
    
    0 讨论(0)
  • 2020-12-02 20:37

    I had a similar problem, I tried to clear all the caches possible (tried almost all the solutions above) and the only thing that worked for me was to kill the expo app and to restart it.

    0 讨论(0)
  • 2020-12-02 20:40

    For those who are using expo-cli

    expo start -c

    0 讨论(0)
  • 2020-12-02 20:41

    If you are using WebStorm, press configuration selection drop down button left of the run button and select edit configurations:

    Double click on Start React Native Bundler at bottom in Before launch section:

    Enter --reset-cache to Arguments section:

    0 讨论(0)
  • 2020-12-02 20:44

    This is what works for me:

    watchman watch-del-all && rm -f yarn.lock && rm -rf node_modules && yarn && yarn start --reset-cache
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题