Jasmine-core避免安装angular-devkit/build-angular。

6

我运行ng serve时出现有关angular-devkit的错误。所以我安装了它,但我收到了以下错误:

npm install @angular-devkit/build-angular            
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: edl-tools@0.0.0
npm ERR! Found: jasmine-core@3.4.0
npm ERR! node_modules/jasmine-core
npm ERR!   dev jasmine-core@"~3.4.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer jasmine-core@">=3.5" from karma-jasmine-html-reporter@1.5.4
npm ERR! node_modules/karma-jasmine-html-reporter
npm ERR!   dev karma-jasmine-html-reporter@"^1.5.1" 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": "edl-tools",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@amcharts/amcharts4": "^4.7.18",
    "@angular/animations": "^8.2.6",
    "@angular/common": "^8.2.14",
    "@angular/compiler": "^8.2.14",
    "@angular/core": "^8.2.14",
    "@angular/forms": "^8.2.14",
    "@angular/http": "7.2.15",
    "@angular/platform-browser": "^8.2.14",
    "@angular/platform-browser-dynamic": "^8.2.14",
    "@angular/router": "^8.2.14",
    "@ng-bootstrap/ng-bootstrap": "^5.1.4",
    "@ng-select/ng-select": "^3.7.1",
    "@progress/kendo-angular-pdf-export": "^1.2.0",
    "@progress/kendo-drawing": "^1.6.0",
    "@progress/kendo-theme-default": "^4.11.1",
    "@swimlane/ngx-datatable": "^14.0.0",
    "@types/bootstrap": "^4.3.1",
    "@types/datatables.net": "^1.10.18",
    "angular-6-datatable": "^0.8.0",
    "angular-datatables": "^6.0.0",
    "angular-google-charts": "^0.1.6",
    "angular-signature": "^1.0.3",
    "angular-signature-pad": "0.0.14",
    "angular2-signature-pad": "^1.0.2",
    "angular2-signaturepad": "^2.11.0",
    "bootstrap": "^4.4.1",
    "bootstrap-datepicker": "1.9.0",
    "bootstrap4-fullscreen-modal": "^1.0.5",
    "canvasjs": "^1.8.3",
    "chart.js": "^2.9.3",
    "chartjs-plugin-annotation": "latest",
    "chartjs-plugin-datalabels": "latest",
    "core-js": "^2.5.0",
    "datatables.net": "^1.10.20",
    "datatables.net-dt": "^1.10.20",
    "file-saver": "2.0.2",
    "font-awesome": "^4.7.0",
    "html2canvas": "^1.0.0-rc.5",
    "jquery": "^3.4.1",
    "jquery-toast-plugin": "^1.3.2",
    "jspdf": "^1.5.3",
    "ng-multiselect-dropdown": "^0.2.10",
    "ng-pick-datetime": "^5.2.6",
    "ng2-charts": "^1.6.0",
    "ng2-table": "^1.3.2",
    "ngx-bootstrap": "^5.3.2",
    "ngx-filter-pipe": "^2.1.2",
    "ngx-spinner": "^6.1.2",
    "ngx-toastr": "^10.2.0",
    "popper.js": "^1.14.3",
    "rxjs": "~6.4.0",
    "rxjs-compat": "^6.5.4",
    "tableexport": "^5.0.2",
    "tslib": "^1.10.0",
    "xlsx": "^0.14.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.803.23",
    "@angular/cli": "^8.3.29",
    "@angular/compiler-cli": "^8.2.14",
    "@angular/language-service": "^8.2.14",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "^2.0.8",
    "@types/jquery": "^3.3.31",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.2.1",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.5.1",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  }
}

那么我该怎么做?

6个回答

7

这个方法对我有用:

我进入“devDependencies”对象

然后将 jasmine-core@3.4.x 改成 jasmine-core@3.8.x


7
似乎 karma-jasmine-html-reporter @ 1.5.4 需要 jasmine-core @ ">=3.5",但你只有 jasmine-core@3.4.x
在 package.json 中将 jasmine-core 更改为 3.5.0 或更高版本,然后再次运行 npm install。也许你应该尝试删除 node_modules 并重新安装。

1
对我来说,我的控制台错误是无法解析依赖项: npm ERR!peer jasmine-core@">=3.7.1" from karma-jasmine-html-reporter@1.6.0所以在我的package.json文件中,我做了这个"jasmine-core": "~3.7.1",并运行了npm install - aghwotu
在未来的Angular项目中,如何避免这个错误?我的node版本是v16.1.0,npm是7.11.2,Angular CLI是Angular CLI: 11.2.12,Angular是Angular: 11.2.13 - aghwotu
我不确定,我认为这些问题可能会一直存在。尝试在升级时运行 ng upgrade 而不是手动升级 package.json。 - AliF50

6

暂时可以通过降级到npm v6来解决问题

npm install -g npm@6.14.15

这对我也完美地起作用了。新版本的npm似乎在一个全新的angular项目中存在问题。 - Tony Stevanovich
这个对我也起作用了。看来旧版本和新版本之间的执行路径是导致问题的原因。正如我注意到的日志所示:..\AppData\Roaming\npm\npm -> ..\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js..\AppData\Roaming\npm\npx -> ..\AppData\Roaming\npm\node_modules\npm\bin\npx-cli.js - Aayushi Gupta
这个降级对我也解决了问题。注意:当前最新版本的 npm6.14.15 - webpreneur
1
@webpreneur 在回答中更新了npm版本。 - Rohit

5

更新您的Angular CLI

npm install -g @angular/cli@latest

接着更新npm

npm install -g npm@latest

升级了这两个之后,它就可以正常工作了。 - Ravi Ji

0

[https://stackoverflow.com/users/5015848/rohit][Rohit]

npm install -g npm@6.14.13

这对我也起作用了。似乎旧版本和新版本之间的执行路径是造成问题的原因。 正如我注意到的那样,日志如下。

..\AppData\Roaming\npm\npm -> ..\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js

..\AppData\Roaming\npm\npx -> ..\AppData\Roaming\npm\node_modules\npm\bin\npx-cli.js


0

这是我所做的:

  1. 更新 angular.cli
npm install -g @angular/cli@latest
  1. node.js 更新至最新的LTS版本(14.16.1)

希望这能有所帮助!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接