【问题标题】:Error when installing material-moment-adapter package in angular以角度安装材料力矩适配器包时出错
【发布时间】:2022-08-14 20:37:24
【问题描述】:

我尝试在终端中运行此命令:

npm i moment @angular/material-moment-adapter.

我收到错误:

 npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
 npm ERR! code ERESOLVE 
 npm ERR! ERESOLVE unable to resolve dependency tree 
 npm ERR! 
 npm ERR! While resolving: xxxxxxxx-xx@0.0.0 npm ERR! Found: @angular/core@10.2.5 
 npm ERR! node_modules/@angular/core 
 npm ERR!   @angular/core@\"^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0\" from the root project 
 npm ERR! npm ERR! Could not resolve dependency: 
 npm ERR! peer @angular/core@\"^14.0.0 || ^15.0.0\" from @angular/material-moment-adapter@14.1.1 
 npm ERR! node_modules/@angular/material-moment-adapter 
 npm ERR!   @angular/material-moment-adapter@\"*\" 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\\xxx\\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\\xxxx\\AppData\\Local\\npm-cache\\_logs\\2022-08-11T06_40_07_646Z-debug-0.log

我尝试运行 npm installnpm i moment 并没有工作。

(其他的“重复问题”不是同一种情况)

这是包json:

{ \"name\": \"证书盲人\", \"版本\": \"0.0.0\", \“脚本\”:{ \"ng\": \"ng\", \"开始\": \"ng服务\", \"build\": \"ng build\", \"测试\": \"ng 测试\", \"lint\": \"ng lint\", \"e2e\": \"ng e2e\", \"格式\": \"更漂亮 --write \"src//*.{ts,html,scss,json}\" \"!src//迁移/**/.\" }, “私人”:是的, \"依赖\": { \"@angular/animations\": \"~10.1.6\", \"@angular/cdk\": \"^10.2.7\", \"@angular/common\": \"~10.1.6\", \"@angular/compiler\": \"~10.1.6\", \"@angular/core\": \"^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0\", \"@angular/forms\": \"~10.1.6\", \"@angular/material\": \"^10.2.7\", \"@angular/platform-b​​rowser\": \"~10.1.6\", \"@angular/platform-b​​rowser-dynamic\": \"~10.1.6\", \"@angular/路由器\": \"~10.1.6\", \"@binssoft/ngx-captcha\": \"^1.0.0\", \"@types/lodash\": \"^4.14.162\", \"cors\": \"^2.8.5\", \"文件保护程序\": \"^2.0.5\", \"扁平化\": \"^3.2.4\", \"lodash\": \"^4.17.20\", \"mat-file-upload\": \"^11.1.2\", \"ng-recaptcha\": \"^8.0.1\", \"ngx-bootstrap\": \"^6.2.0\", \"更漂亮\": \"^2.1.2\", \"rxjs\": \"~6.6.0\", \"tslib\": \"^2.0.0\", \"zone.js\": \"~0.10.2\" }, \"devDependencies\": { \"@angular-devkit/build-angular\": \"~0.1001.7\", \"@angular/cli\": \"^10.2.3\", \"@angular/compiler-cli\": \"~10.1.6\", \"@types/file-saver\": \"^2.0.1\", \"@types/jasmine\": \"~3.5.0\", \"@types/jasminewd2\": \"~2.0.3\", \"@types/node\": \"^12.11.1\", \"codelyzer\": \"^6.0.0\", \"茉莉花核\": \"~3.6.0\", \"jasmine-spec-reporter\": \"~5.0.0\", \"量角器\": \"~7.0.0\", \"ts-node\": \"~8.3.0\", \"tslint\": \"~6.1.0\", \"打字稿\": \"~4.0.2\" }, \"peerDependencies\": { \"@angular/core\": \"^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0\" } }

.

  • 似乎对等依赖项导致了问题,请尝试执行npm install moment --force,如果可行,那么您必须注意哪个对等依赖项失败了\'
  • 有几个错误,这是第一个:peerOptional @angular/animations@\"14.1.1\" from @angular/platform-b​​rowser@14.1.1
  • 谁能帮忙??

标签: angular installation angular-material package compatibility


【解决方案1】:

为什么你会收到错误

您正在尝试将 @angular/material-moment-adapter 的最新版本 (14.1.1) 安装到主版本 10 上的 Angular 项目中。 这会导致依赖冲突,因为不同的 Angular 包相互依赖,并且大多需要相同的主版本。

您可以从此错误消息中阅读:

对等 @angular/core@"^14.0.0 || ^15.0.0" 来自 @angular/material-moment-adapter@14.1.1

它说,@angular/material-moment-adapter 想要 @angular/core 版本 14.x.x15.x.x

你可以做什么:

在您的情况下,我看到了两种可能的方法:

  1. 通过运行安装旧版本的@angular/material-moment-adapter

    npm i @angular/material-moment-adapter@10 moment

    1. 升级到所有 Angular 包的主要版本 14(逐步)。请参阅their update guide 寻求帮助。

    旁注

    1. 您在 package.json 的依赖项部分中的 @angular/core 依赖项看起来很奇怪:

      "@angular/core": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0",

      使用此设置,您基本上允许 6.0.0 和最新 10ish 版本之间的任何版本。但是 10.x.x 以外的任何其他版本都会导致与其他依赖项发生冲突。因此,我建议在此处使用不同的版本规范,例如为@angular/common 指定的版本规范,依此类推(= ~10.1.6)。

      1. 您还获得了@angular/core 作为对等依赖项。这意味着,安装您的软件包的任何人都需要在此处列出的任何版本中安装 @angular/core

      "@angular/core": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0"

      如果您的工作区不包含应该由其他库或应用程序使用的库,那么您可能希望删除此 peerDependencies 条目。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 2012-06-16
    相关资源
    最近更新 更多