首页指南参考教程

清除 macOS 和 Linux 上的打包程序缓存

了解如何在 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 和 Yarn

¥Expo CLI and Yarn

Terminal
# 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 和 npm

¥Expo CLI and npm

Terminal
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 和 Yarn

¥React Native CLI and Yarn

Terminal
# 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 和 npm

¥React Native CLI and npm

Terminal
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 转换缓存
Expo 中文网 - 粤ICP备13048890号