react如何卸载
卸载 React 项目
卸载 React 项目通常指从系统中移除 React 相关的依赖或项目文件。以下是几种常见的卸载场景及方法:
移除本地 React 项目
如果需要完全删除本地创建的 React 项目,直接删除项目文件夹即可。React 项目本质是一个包含依赖的目录,删除文件夹会连带移除所有代码和依赖。
rm -rf your-react-project
卸载全局 React 相关工具
如果通过 create-react-app 或其他 CLI 工具全局安装了 React 脚手架,可通过 npm 或 yarn 卸载全局包:

卸载 create-react-app
npm uninstall -g create-react-app
# 或
yarn global remove create-react-app
检查全局包列表
确认是否已卸载:
npm list -g --depth=0
# 或
yarn global list
清理项目依赖
若仅需移除项目中的 React 依赖,进入项目目录后删除 node_modules 和依赖声明文件:

cd your-project
rm -rf node_modules package-lock.json
重新安装依赖时使用:
npm install
清除缓存
某些情况下可能需要清理 npm/yarn 缓存:
npm
npm cache clean --force
yarn
yarn cache clean
注意事项
- 删除项目前确保已备份重要代码。
- 全局工具卸载后,可能需要手动删除残留的配置文件(如
~/.npm或~/.yarn)。






