如何修复“npm ERR!在您的 package-lock.json 中发现错误”

lab*_*abi 6 npm

我在 npm 中收到以下错误。请问这是什么意思?我该如何修复此错误?

npm ERR! code ELOCKVERIFY
npm ERR! Errors were found in your package-lock.json, run  npm install  to fix them.
npm ERR!     Invalid: lock file's @angular/animations@12.1.3 does not satisfy @angular/animations@~12.1.0-
npm ERR!     Invalid: lock file's @angular/common@12.1.3 does not satisfy @angular/common@~12.1.0-   
npm ERR!     Invalid: lock file's @angular/compiler@12.1.3 does not satisfy @angular/compiler@~12.1.0-    
npm ERR!     Invalid: lock file's @angular/core@12.1.3 does not satisfy @angular/core@~12.1.0-
npm ERR!     Invalid: lock file's @angular/forms@12.1.3 does not satisfy @angular/forms@~12.1.0-
npm ERR!     Invalid: lock file's @angular/platform-browser@12.1.3 does not satisfy @angular/platform-browser@~12.1.0-
npm ERR!     Invalid: lock file's @angular/platform-browser-dynamic@12.1.3 does not satisfy @angular/platform-browser-dynamic@~12.1.0-
npm ERR!     Invalid: lock file's @angular/router@12.1.3 does not satisfy @angular/router@~12.1.0-
npm ERR!     Invalid: lock file's @angular/compiler-cli@12.1.3 does not satisfy @angular/compiler-cli@~12.1.0-
Run Code Online (Sandbox Code Playgroud)

Mat*_*zen 10

我知道有时以前的解决方案并不总是有效,最新版本的 Angular CLI 似乎就是这种情况。

以下是我用来解决问题的步骤:

  1. 删除 package-lock.jsonrm package-lock.json
  2. 在 package.json 的依赖项和 devDependencies 部分下,更新如下所示的任何版本号~12.1.0-
  3. 然后运行npm install

希望这可以帮助您解决您遇到的问题。

祝你有个好的一天 :)

马修


JAW*_*ber 6

不幸的是,在这种情况下删除package-lock.json和运行npm install将不起作用。运行后我遇到了完全相同ng new的错误。在回顾了npm 版本控制并绞尽脑汁之后,我执行了以下操作(修复了它):

  1. 已删除package-lock.json
  2. 已删除node_modules
  3. npm cache clean --force
  4. 编辑package.json每个引用的库并将“0-”更改为“3”(例如"@angular/animations": "~12.1.3"代替"@angular/animations": "~12.1.0-"

我不知道所有步骤是否都是完全必要的,但每当我开始遇到任何没有明显修复的 npm 奇怪问题时,我总是执行步骤 1 到 3。

至于错误消息的含义,每一行都表明已安装的库的版本未能落在您指定的(在您的package.json)您将接受的版本范围内。

对我来说,神秘的是如果我指定了 12.1.0,那么如何/为什么会安装 12.1.3 版本package.json。尾随的“-”显然与它有关,但我没有看到它是 npm 版本控制语法的一部分(上面链接)。虽然语义版本控制规范确实允许使用连字符来指示预发布版本,但它后面必须有一些东西。