了解如何在 macOS 和 Linux 上使用 Yarn 或 npm 与 Expo CLI 或 React Native CLI 时清除打包器缓存。
需要清除 Windows 上的开发缓存吗?在这里找到相关命令。
¥Need to clear development caches on Windows? Find the relevant commands here.
有许多与你的项目关联的不同缓存可能会阻止你的项目按预期运行。清除缓存有时可以帮助你解决与旧的或损坏的数据相关的问题,并且在故障排除和调试时通常很有用。
¥There are a number of different caches associated with your project that can prevent your project from running as intended. Clearing a cache sometimes can help you work around issues related to stale or corrupt data and is often useful when troubleshooting and debugging.
要清除各种缓存,请运行:
¥To clear the various caches, run:
¥Expo CLI and Yarn
# With Yarn workspaces, you may need to delete node_modules in each workspace
-
rm -rf node_modules
-
yarn cache clean
-
yarn
-
watchman watch-del-all
-
rm -fr $TMPDIR/haste-map-*
-
rm -rf $TMPDIR/metro-cache
-
npx expo start --clear
¥Expo CLI and npm
-
rm -rf node_modules
-
npm cache clean --force
-
npm install
-
watchman watch-del-all
-
rm -fr $TMPDIR/haste-map-*
-
rm -rf $TMPDIR/metro-cache
-
npx expo start --clear
¥React Native CLI and Yarn
# With Yarn workspaces, you may need to delete node_modules in each workspace
-
rm -rf node_modules
-
yarn cache clean
-
yarn
-
watchman watch-del-all
-
rm -fr $TMPDIR/haste-map-*
-
rm -rf $TMPDIR/metro-cache
-
yarn start -- --reset-cache
¥React Native CLI and npm
-
rm -rf node_modules
-
npm cache clean --force
-
npm install
-
watchman watch-del-all
-
rm -fr $TMPDIR/haste-map-*
-
rm -rf $TMPDIR/metro-cache
-
npm start -- --reset-cache
¥What these commands are doing
在运行之前了解在互联网上找到的命令是一个好习惯。我们解释了下面针对 Expo CLI、npm 和 Yarn 的每个命令,但相应的命令 React Native CLI 具有相同的行为。
¥It is a good habit to understand commands you find on the internet before you run them. We explain each command below for Expo CLI, npm, and Yarn, but the corresponding commands React Native CLI have the same behavior.
命令 | 描述 |
---|---|
rm -rf node_modules | 清除项目的所有依赖 |
yarn cache clean | 清除全局 Yarn 缓存 |
npm cache clean --force | 清除全局 npm 缓存 |
yarn /npm install | 重新安装所有依赖 |
watchman watch-del-all | 重置 watchman 文件监视器 |
rm -rf $TMPDIR/<cache> | 清除给定的打包程序/打包程序缓存文件或目录 |
npx expo start --clear | 重新启动开发服务器并清除 JavaScript 转换缓存 |