[英]How to clear react-native cache?
在react-native开发中,在构建app时使用了多个缓存:
我也错过了什么吗? 因为我正在尝试清除 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 种不同实例的解决方案。
RN <0.50 -
watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache
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
watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache verify && npm install && npm start -- --reset-cache
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 种情况对您不起作用,您也可以滚动浏览并找到可能的解决方案。
清除 React Native 项目的缓存:如果您确定模块存在,请尝试以下步骤:
目前,它是使用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 缓存之外,您可能还需要重置模拟器或清理构建等。
你试过 gradle cleanBuildCache 吗?
https://developer.android.com/studio/build/build-cache.html#clear_the_build_cache
我遇到了类似的问题,我试图清除所有可能的缓存(尝试了上面几乎所有的解决方案),唯一对我有用的方法就是杀死 expo 应用程序并重新启动它。
我今天也进入了这个问题。 原因有点傻vscode
自动从express-validator
导入了一些东西并导致了错误。
只是提到这一点,以防有人已完成清除缓存/删除模块的所有步骤或其他操作。
嗯..我想分享我对这个问题的经验:
我遇到了这个问题,当我打开任务管理器时,我注意到许多任务正在执行,并且它们链接到我的项目文件夹。
所以我重新启动了我的电脑,当它打开时,我可以安装我需要的所有东西,所以问题自己解决了,它对我有用,希望这能帮助别人......
删除/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.