This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

清除 Windows 上的 bundler 缓存

编辑页面

了解在 Windows 上使用 Expo CLI 或 React Native CLI 时,如何清除 Yarn 或 npm 的 bundler 缓存。


与你的项目相关联的缓存有很多种,它们可能会阻止你的项目按预期运行。清除缓存有时可以帮助你绕过与过期或损坏数据相关的问题,并且在排查和调试时通常很有用。

Expo CLI 和 Yarn

Terminal
# 使用 Yarn workspaces 时,您可能需要删除每个工作区中的 node_modules
rm -rf node_modules

yarn cache clean

yarn

watchman watch-del-all

del %localappdata%Temphaste-map-*

del %localappdata%Tempmetro-cache

npx expo start --clear

Expo CLI 和 npm

Terminal
rm -rf node_modules

npm 缓存清理 --force

npm install

watchman watch-del-all

del %localappdata%Temphaste-map-*

del %localappdata%Tempmetro-cache

npx expo start --clear

React Native CLI 和 Yarn

Terminal
# 使用 Yarn workspaces 时,你可能需要删除每个 workspace 中的 node_modules
rm -rf node_modules

yarn cache clean

yarn

watchman watch-del-all

del %localappdata%Temphaste-map-*

del %localappdata%Tempmetro-cache

yarn start -- --reset-cache

React Native CLI 和 npm

Terminal
rm -rf node_modules

npm cache clean --force

npm install

watchman watch-del-all

del %localappdata%Temphaste-map-*

del %localappdata%Tempmetro-cache

npm start -- --reset-cache

这些命令在做什么

在运行你在网上找到的命令之前,先了解它们的作用是个好习惯。下面我们分别解释 Expo CLI、npm 和 Yarn 的每个命令,不过 React Native CLI 中对应的命令具有相同的行为。

命令描述
del node_modules清除项目的所有依赖项
yarn cache clean清除全局 Yarn 缓存
npm cache clean --force清除全局 npm 缓存
yarn/npm install重新安装所有依赖项
watchman watch-del-all重置 watchman 文件监视器
del %localappdata%\Temp/<cache>清除指定的打包器/捆绑器缓存文件或目录
npx expo start --clear重新启动开发服务器并清除 JavaScript 转换缓存