npm 安装报错?清理 npm 缓存
依赖反复安装失败、校验出错时,用 npm cache verify 修复缓存,或 clean --force 彻底清空重来。
先运行 `npm cache verify` 修复缓存;问题依旧时运行 `npm cache clean --force` 彻底清空缓存。
01命令
命令
$ npm cache clean --force
# or verify/repair instead:
npm cache verify02作用说明
缓存里出现写了一半的包文件时,npm 会报 integrity 校验失败,或者明明存在的版本却说找不到。npm cache verify 会检查每个缓存包、丢弃损坏文件并回收空间——这是温和的第一步。npm cache clean --force 则删除整个缓存;npm 强制要求加 --force,因为清空缓存意味着所有包要重新下载,但它能解决最顽固的问题。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- npm-cache (v9) | npm Docs依据: npm cache clean --force and npm cache verify are documented for the npm cache command.
- npm-cache | npm Docs依据: Documents npm cache clean --force (cleaning requires --force) and npm cache verify to validate and garbage-collect the cache.
最后验证: 2026-09-19 · 分类: 开发者