为什么 npm 尝试使用我的 package.json 中未引用的包版本?
Why is npm attempting to use a package version not referenced in my package.json?
我已经创建了一个 Angular + .NET 5 网络应用程序,并且正在尝试 运行 npm i
安装这些包。当我这样做时,出现以下错误:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: badgemanagement.admin.webui@0.0.0
npm ERR! Found: @angular/compiler@13.2.3
npm ERR! node_modules/@angular/compiler
npm ERR! @angular/compiler@"13.2.3" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/compiler@"13.2.5" from @angular/compiler-cli@13.2.5
npm ERR! node_modules/@angular/compiler-cli
npm ERR! dev @angular/compiler-cli@"^13.2.3" from the root project
npm ERR! peer @angular/compiler-cli@"^13.0.0" from @angular-devkit/build-angular@13.2.5
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! dev @angular-devkit/build-angular@"^13.2.4" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\...\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\...\AppData\Local\npm-cache\_logs22-03-07T14_52_08_376Z-debug.log
正如您从我下面的 package.json 文件中看到的那样,我没有引用 @angular/compiler-cli@13.2.5
或 @angular-devkit/build-angular@13.2.5
。如果我猜的话,它可能正在尝试使用安装的全局 cli 版本,可能是 13.2.5,但为什么它会完全忽略 package.json 中引用的版本?当然,我可以使用 --force
或 --legacy-peer-deps
,但是当 package.json 中引用了正确的依赖项时,我真的应该告诉它忽略依赖项吗?这对我来说没有意义。我已经完成了 npm cache clean --force
,但没有帮助。假设我想使用这个特定版本,处理这种情况的“正确”方法是什么?
package.json
{
"name": "myapp",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build:ssr": "ng run myapp:server:dev",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/common": "13.2.3",
"@angular/compiler": "13.2.3",
"@angular/core": "13.2.3",
"@angular/forms": "13.2.3",
"@angular/platform-browser": "13.2.3",
"@angular/platform-browser-dynamic": "13.2.3",
"@angular/platform-server": "13.2.3",
"@angular/router": "13.2.3",
"bootstrap": "^4.6.0",
"core-js": "^3.8.3",
"jquery": "^3.5.1",
"oidc-client": "^1.11.3",
"popper.js": "^1.16.0",
"rxjs": "^6.6.3",
"zone.js": "0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^13.2.4",
"@angular/cli": "^13.2.4",
"@angular/compiler-cli": "^13.2.3",
"@angular/language-service": "^13.2.3",
"@types/jasmine": "~3.4.4",
"@types/jasminewd2": "~2.0.8",
"@types/node": "~12.11.6",
"codelyzer": "^6.0.2",
"ini": "^1.3.7",
"jasmine-core": "3.8",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^6.3.16",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.5.4",
"typescript": "4.5.5"
},
"optionalDependencies": {
"node-sass": "^7.0.1",
"protractor": "^7.0.0",
"ts-node": "~8.4.1",
"tslint": "^6.1.0"
},
"resolutions": {
"url-parse": ">=1.5.0",
"lodash": ">=4.17.21"
}
}
看起来是因为插入符号 ^
会尝试获取次要版本。尝试删除 package-lock.json
并删除版本号前的插入符号。
或者你也可以试试yarn install
我已经创建了一个 Angular + .NET 5 网络应用程序,并且正在尝试 运行 npm i
安装这些包。当我这样做时,出现以下错误:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: badgemanagement.admin.webui@0.0.0
npm ERR! Found: @angular/compiler@13.2.3
npm ERR! node_modules/@angular/compiler
npm ERR! @angular/compiler@"13.2.3" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/compiler@"13.2.5" from @angular/compiler-cli@13.2.5
npm ERR! node_modules/@angular/compiler-cli
npm ERR! dev @angular/compiler-cli@"^13.2.3" from the root project
npm ERR! peer @angular/compiler-cli@"^13.0.0" from @angular-devkit/build-angular@13.2.5
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! dev @angular-devkit/build-angular@"^13.2.4" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\...\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\...\AppData\Local\npm-cache\_logs22-03-07T14_52_08_376Z-debug.log
正如您从我下面的 package.json 文件中看到的那样,我没有引用 @angular/compiler-cli@13.2.5
或 @angular-devkit/build-angular@13.2.5
。如果我猜的话,它可能正在尝试使用安装的全局 cli 版本,可能是 13.2.5,但为什么它会完全忽略 package.json 中引用的版本?当然,我可以使用 --force
或 --legacy-peer-deps
,但是当 package.json 中引用了正确的依赖项时,我真的应该告诉它忽略依赖项吗?这对我来说没有意义。我已经完成了 npm cache clean --force
,但没有帮助。假设我想使用这个特定版本,处理这种情况的“正确”方法是什么?
package.json
{
"name": "myapp",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build:ssr": "ng run myapp:server:dev",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/common": "13.2.3",
"@angular/compiler": "13.2.3",
"@angular/core": "13.2.3",
"@angular/forms": "13.2.3",
"@angular/platform-browser": "13.2.3",
"@angular/platform-browser-dynamic": "13.2.3",
"@angular/platform-server": "13.2.3",
"@angular/router": "13.2.3",
"bootstrap": "^4.6.0",
"core-js": "^3.8.3",
"jquery": "^3.5.1",
"oidc-client": "^1.11.3",
"popper.js": "^1.16.0",
"rxjs": "^6.6.3",
"zone.js": "0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^13.2.4",
"@angular/cli": "^13.2.4",
"@angular/compiler-cli": "^13.2.3",
"@angular/language-service": "^13.2.3",
"@types/jasmine": "~3.4.4",
"@types/jasminewd2": "~2.0.8",
"@types/node": "~12.11.6",
"codelyzer": "^6.0.2",
"ini": "^1.3.7",
"jasmine-core": "3.8",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^6.3.16",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.5.4",
"typescript": "4.5.5"
},
"optionalDependencies": {
"node-sass": "^7.0.1",
"protractor": "^7.0.0",
"ts-node": "~8.4.1",
"tslint": "^6.1.0"
},
"resolutions": {
"url-parse": ">=1.5.0",
"lodash": ">=4.17.21"
}
}
看起来是因为插入符号 ^
会尝试获取次要版本。尝试删除 package-lock.json
并删除版本号前的插入符号。
或者你也可以试试yarn install