How to clear react-native cache?

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

    Have you tried gradle cleanBuildCache?

    https://developer.android.com/studio/build/build-cache.html#clear_the_build_cache

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

    Clearing the Cache of your React Native Project: if you are sure the module exists, try this steps:

    1. Clear watchman watches: npm watchman watch-del-all
    2. Delete node_modules: rm -rf node_modules and run yarn install
    3. Reset Metro's cache: yarn start --reset-cache
    4. Remove the cache: rm -rf /tmp/metro-*
    0 讨论(0)
  • 2020-12-02 20:23

    For React Native Init approach (without expo) use:

    npm start -- --reset-cache
    
    0 讨论(0)
  • 2020-12-02 20:32

    You can clean cache in React Native >= 0.50 and npm > 5 :

    watchman watch-del-all && 
    rm -rf $TMPDIR/react-native-packager-cache-* &&
    rm -rf $TMPDIR/metro-bundler-cache-* && 
    rm -rf node_modules/ 
    && npm cache clean --force &&
    npm install && 
    npm start -- --reset-cache
    

    Apart from cleaning npm cache you might need to reset simulator or clean build etc.

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

    I went into this issue today, too. The cause was kinda silly -- vscode auto imported something from express-validator and caused the bug.

    Just mentioning this in case anyone has done all the steps to clear cache/ delete modules or what not.

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

    Clearing the Cache of your React Native Project:

    npm < 6.0 and RN < 0.50:

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

    npm >= 6.0 and 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 --force &&
     npm install && npm start -- --reset-cache
    
    0 讨论(0)
提交回复
热议问题