构建 .NET Core + Angular 项目时出现问题
我有一个未知的项目。我需要做一些小修复。 我尝试过构建它们:
dotnet 发布 -c 发布 -r win-x64 --self-contained false --output “D:\路径到输出目录\项目”
出现错误:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: @angular/[email protected]
npm ERR! node_modules/@angular/common
npm ERR! @angular/common@"8.0.0" from the root project
npm ERR! peer @angular/common@"^8.0.0 || ^9.0.0-0" from @angular/[email protected]
npm ERR! node_modules/@angular/cdk
npm ERR! @angular/cdk@"^8.2.3" from the root project
npm ERR! 8 more (@angular/forms, @angular/platform-browser, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@">=10.0.0 <12.0.0" from [email protected]
npm ERR! node_modules/angular-recaptcha3
npm ERR! angular-recaptcha3@"^2.0.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @angular/[email protected]
npm ERR! node_modules/@angular/common
npm ERR! peer @angular/common@">=10.0.0 <12.0.0" from [email protected]
npm ERR! node_modules/angular-recaptcha3
npm ERR! angular-recaptcha3@"^2.0.0" 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.
在“package.json”中我看到:
{
"name": "project1",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build:ssr": "ng run project1:server:dev",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "8.0.0",
"@angular/cdk": "^8.2.3",
"@angular/common": "8.0.0",
"@angular/compiler": "8.0.0",
"@angular/core": "8.0.0",
"@angular/forms": "8.0.0",
"@angular/platform-browser": "8.0.0",
"@angular/platform-browser-dynamic": "8.0.0",
"@angular/platform-server": "8.0.0",
"@angular/router": "8.0.0",
"@ng-select/ng-select": "^3.7.0",
"@nguniversal/module-map-ngfactory-loader": "8.0.0-rc.1",
"@types/html2canvas": "^1.0.0",
"angular-recaptcha3": "^2.0.0",
"angular-tree-component": "^8.5.6",
"angular2-text-mask": "^9.0.0",
"aspnet-prerendering": "^3.0.1",
"bootstrap": "^4.4.1",
"browserslist": "^4.8.2",
"caniuse-lite": "^1.0.30001016",
"ckeditor4-angular": "^2.1.0",
"core-js": "^2.6.11",
"cors": "^2.8.5",
"date-fns": "^2.16.1",
"jquery": "3.4.1",
"jspdf": "^1.4.1",
"leaflet-image": "^0.4.0",
"moment": "^2.24.0",
"ng-pick-datetime": "^7.0.0",
"oidc-client": "^1.10.1",
"popper.js": "^1.16.0",
"rxjs": "^6.5.3",
"subsink": "^1.0.2",
"text-mask-addons": "^3.8.0",
"uuid": "^3.3.3",
"web-animations-js": "^2.3.2",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.800.6",
"@angular/cli": "8.0.6",
"@angular/compiler-cli": "8.0.0",
"@angular/language-service": "8.0.0",
"@types/jasmine": "^3.5.0",
"@types/jasminewd2": "^2.0.8",
"@types/node": "~11.10.5",
"codelyzer": "^5.2.1",
"jasmine-core": "~3.3.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^2.1.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"typescript": "3.4.5"
},
"optionalDependencies": {
"node-sass": "^4.9.3",
"protractor": "~5.4.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
}
}
应用程序需要 Angular/Common 版本 8。 Angular-recaptcha3 需要 Angular/Common 版本 10+。 我尝试过不同版本的 angular-recaptcha3 - 没有任何帮助。 我尝试在应用程序中设置 Angular/Common 版本 10 - 结果甚至出现更多包冲突。
以前的开发人员告诉我他可以毫无错误地构建。 我不明白这怎么可能。
在这种情况下如何统一所有包版本? 你能帮助我吗,我是 NPM 依赖项的新手。
我找到了冲突的根本原因,并使用“--legacy-peer-deps”等选项运行 npm。只是 Angular 8 需要 Node 12 版本,而不是我之前安装的 18 版本。 构建通过后就OK了。