簡體   English   中英

如何清除react-native緩存?

[英]How to clear react-native cache?

在react-native開發中,在構建app時使用了多個緩存:

  1. React-native 打包器緩存
  2. 模擬器緩存
  3. Java 端緩存 (.gradle) 文件夾(僅在 android 中)
  4. npm 緩存(如果相關?)

我也錯過了什么嗎? 因為我正在嘗試清除 react-native 中的緩存,以便能夠重復僅在首次使用時出現的錯誤。 但是清除上面的那些緩存並沒有幫助。 這是在 android 上。當應用程序正在構建時,大多數行都不會像預期的那樣說 UP-TO-DATE,因為我清除了緩存。

但是,仍然有很多行打印此文本。 喜歡:

應用程序:預構建最新

應用程序:preDebugBuild 最新

:app:preReleaseBuild 最新版本

問題是,如何清除與 react-native 開發相關的整個緩存?

對於 React Native Init 方法(沒有 expo)使用:

npm start -- --reset-cache

清除 React Native 項目的緩存:

npm < 6.0 和 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 和 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

最簡單的一個(react native、npm 和 expo)

對於 React Native

react-native start --reset-cache

對於 npm

npm start -- --reset-cache

世博會

expo start -c

試試這個

react-native start --reset-cache

對於那些使用 expo-cli 的人

博覽會開始 -c

這對我有用:

watchman watch-del-all && rm -f yarn.lock && rm -rf node_modules && yarn && yarn start --reset-cache

這是 GitHub 上的一個很棒的討論,對我幫助很大。 Jarret Moses 清除 React Native 項目的緩存

有針對 4 種不同實例的解決方案。

  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

解決方案類似於Vikram Biwal 的答案。

並且在給定的鏈接中有下面的討論,因此即使上述 4 種情況對您不起作用,您也可以滾動瀏覽並找到可能的解決方案。

如果您使用的是WebStorm ,請按運行按鈕左側的配置選擇下拉按鈕並選擇編輯配置:

編輯配置

雙擊Start React Native Bundler Before launch部分底部的Start React Native Bundler

發射前

Arguments部分輸入--reset-cache

爭論

清除 React Native 項目的緩存:如果您確定模塊存在,請嘗試以下步驟:

  1. 清除守望者手表:npm watchman watch-del-all
  2. 刪除 node_modules: rm -rf node_modules 並運行 yarn install
  3. 重置 Metro 的緩存:yarn start --reset-cache
  4. 刪除緩存:rm -rf /tmp/metro-*

目前,它是使用npx構建的,因此需要更新。

終端: npx react-native start --reset-cache

IOS:Xcode -> 產品 -> 清理構建文件夾

Android : Android Studio -> Build -> Clean Project

以下命令對我適用於 Android 和 Yarn,

cd android && ./gradlew cleanBuildCache && cd .. &&
watchman watch-del-all && rm -rf node_modules/ &&
rm -rf $TMPDIR/react-native-packager-cache-* &&
rm -rf $TMPDIR/metro-bundler-cache-* &&  
yarn cache clean && yarn install && 
yarn start --reset-cache

您可以清除 React Native >= 0.50 和 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

除了清理 npm 緩存之外,您可能還需要重置模擬器或清理構建等。

我遇到了類似的問題,我試圖清除所有可能的緩存(嘗試了上面幾乎所有的解決方案),唯一對我有用的方法就是殺死 expo 應用程序並重新啟動它。

我今天也進入了這個問題。 原因有點傻vscode自動從express-validator導入了一些東西並導致了錯誤。

只是提到這一點,以防有人已完成清除緩存/刪除模塊的所有步驟或其他操作。

嗯..我想分享我對這個問題的經驗:

我遇到了這個問題,當我打開任務管理器時,我注意到許多任務正在執行,並且它們鏈接到我的項目文件夾。

所以我重新啟動了我的電腦,當它打開時,我可以安裝我需要的所有東西,所以問題自己解決了,它對我有用,希望這能幫助別人......

清除 IOS/Xcode 中的緩存

刪除/Users/{YOUR_USERNAME}/Library/Developer/Xcode/DerivedData/文件夾,然后重試。

rm ~/Library/Developer/Xcode/DerivedData/* 

對於 android 和 Npm

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

反應本機

 npm start -r-cache

或者

yarn cache clean

Expo

expo start -c

在您的終端中運行: expo prebuild --clean

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM