【问题标题】:Angular app error when running npm install - Could not resolve dependency运行 npm install 时出现 Angular 应用程序错误 - 无法解析依赖项
【发布时间】:2021-05-01 06:33:23
【问题描述】:

我有一个 Angular 9 (* UPDATE,这意味着 Angular 11),它是在 Ubuntu 和 Mac 机器上开发的。以下命令没有问题:

npm install

所以现在我需要将它部署到 Linux Centos 7 服务器。所以我已经对它进行了 Docker 化。当Dockerfile要执行npm install时,会得到如下错误:

Step 4/13 : RUN npm install
 ---> Running in 42f10bf7732c
npm notice 
npm notice New patch version of npm available! 7.4.0 -> 7.4.3
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.4.3>
npm notice Run `npm install -g npm@7.4.3` to update!
npm notice 
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: nexct-ng-ui@0.0.0
npm ERR! Found: @angular/common@11.0.9
npm ERR! node_modules/@angular/common
npm ERR!   @angular/common@"~11.0.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@"^10.2.2" from angular-datatables@10.1.0
npm ERR! node_modules/angular-datatables
npm ERR!   angular-datatables@"^10.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.
npm ERR! 
npm ERR! See /root/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-01-27T12_02_45_235Z-debug.log

有什么想法吗?

附加信息:

我尝试查看建议的日志:

/root/.npm/eresolve-report.txt: No such file or directory
/root/.npm/_logs/2021-01-27T12_02_45_235Z-debug.log: No such file or directory

package.json

{
  "name": "nexct-ng-ui",
  "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": {
    "@angular/animations": "~11.0.0",
    "@angular/common": "~11.0.0",
    "@angular/compiler": "~11.0.0",
    "@angular/core": "~11.0.0",
    "@angular/forms": "~11.0.0",
    "@angular/platform-browser": "~11.0.0",
    "@angular/platform-browser-dynamic": "~11.0.0",
    "@angular/router": "~11.0.0",
    "@fortawesome/fontawesome-free": "^5.15.1",
    "angular-datatables": "^10.0.0",
    "bootstrap": "^4.5.3",
    "datatables.net": "^1.10.22",
    "datatables.net-dt": "^1.10.22",
    "jquery": "^3.5.1",
    "ng-recaptcha": "^6.0.2",
    "popper.js": "^1.16.1",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1100.1",
    "@angular/cli": "~11.0.1",
    "@angular/compiler-cli": "~11.0.0",
    "@types/datatables.net": "^1.10.19",
    "@types/jasmine": "~3.6.0",
    "@types/jquery": "^3.5.4",
    "@types/node": "^12.11.1",
    "codelyzer": "^6.0.0",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~5.1.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~4.0.2"
  }
}

【问题讨论】:

标签: angular docker npm


【解决方案1】:

您是说您的应用程序是用 ng 9 编写的,但有一些错误行,例如 npm ERR! Found: @angular/common@11.0.9angular-datatables@"^10.0.0",其中 ng 版本为 11。这可能是问题所在,因为 angular-datatables 版本 10.0 之间存在依赖关系.0 和 angular 11. 修复它,它会正常工作

【讨论】:

  • 感谢您的回答,我对Angular的版本有误。我们正在使用 Angular 11。我现在已经发布了 package.json 文件。
  • 谢谢,解决了。我更新为"angular-datatables": "^11.1.0"
  • 乐于帮助@Richard
猜你喜欢
  • 1970-01-01
  • 2021-07-07
  • 2021-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-26
  • 2020-02-20
  • 1970-01-01
相关资源
最近更新 更多