# npm 错误！代码 EUSAGE npm 错误！`npm ci` 只能在 package-lock.json 或 npm-shrinkwrap.json 与 package.json 同步时安装包

- **ID:** `cicd/npm-ci-lockfile-outdated`
- **领域:** cicd
- **类别:** install_error
- **错误码:** `EUSAGE`
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

npm ci 失败，因为 package-lock.json 与 package.json 不同步，通常是由于手动编辑 package.json 而未运行 npm install 更新锁文件。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| npm 9.6.0 | active | — | — |
| Node.js 18.16.0 | active | — | — |
| npm 10.2.0 | active | — | — |

## 解决方案

1. ```
   Regenerate the lockfile by running: npm install && git add package-lock.json && git commit -m 'Update lockfile'. Then retry npm ci.
   ```
2. ```
   If the discrepancy is due to version ranges, pin exact versions in package.json to avoid lockfile drift.
   ```

## 无效尝试

- **** — Deleting node_modules and package-lock.json and re-running npm install may break CI reproducibility by generating a different lockfile. (20% 失败率)
- **** — Running npm audit fix can modify package.json or lockfile, introducing unintended changes. (30% 失败率)
