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

了解如何在 macOS 和 Linux 上使用 Yarn 或 npm 与 Expo CLI 或 React Native CLI 时清除打包器缓存。


需要在 Windows 上清除开发缓存吗?在这里查找相关命令。

你的项目有许多不同的缓存,这些缓存可能会阻止你的项目按预期运行。清除缓存有时可以帮助你解决与陈旧或损坏数据相关的问题,并且在排查和调试时通常很有用。

🌐 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 转换缓存