安装 AWS CDK 构造库时出现“ERESOLVE 无法解析依赖关系树”

时间:2021-03-27 00:51:54

标签: node.js amazon-web-services npm aws-cdk

$ npm i @aws-cdk/aws-ec2
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: cdk_sample@0.1.0
npm ERR! Found: @aws-cdk/core@1.95.0
npm ERR! node_modules/@aws-cdk/core
npm ERR!   @aws-cdk/core@"1.95.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @aws-cdk/core@"1.95.1" from @aws-cdk/aws-iam@1.95.1
npm ERR! node_modules/@aws-cdk/aws-iam
npm ERR!   peer @aws-cdk/aws-iam@"1.95.1" from @aws-cdk/aws-ec2@1.95.1
npm ERR!   node_modules/@aws-cdk/aws-ec2
npm ERR!     @aws-cdk/aws-ec2@"*" from the root project
npm ERR!   peer @aws-cdk/aws-iam@"1.95.1" from @aws-cdk/aws-cloudwatch@1.95.1
npm ERR!   node_modules/@aws-cdk/aws-cloudwatch
npm ERR!     peer @aws-cdk/aws-cloudwatch@"1.95.1" from @aws-cdk/aws-ec2@1.95.1
npm ERR!     node_modules/@aws-cdk/aws-ec2
npm ERR!       @aws-cdk/aws-ec2@"*" 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 /home/sean/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/sean/.npm/_logs/2021-03-27T00_41_58_124Z-debug.log
sean@desktop:~/WebstormProjects/cdkSample$ npm i @aws-cdk/aws-ec2
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: cdk_sample@0.1.0
npm ERR! Found: @aws-cdk/core@1.95.0
npm ERR! node_modules/@aws-cdk/core
npm ERR!   @aws-cdk/core@"1.95.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @aws-cdk/core@"1.95.1" from @aws-cdk/aws-iam@1.95.1
npm ERR! node_modules/@aws-cdk/aws-iam
npm ERR!   peer @aws-cdk/aws-iam@"1.95.1" from @aws-cdk/aws-ec2@1.95.1
npm ERR!   node_modules/@aws-cdk/aws-ec2
npm ERR!     @aws-cdk/aws-ec2@"*" from the root project
npm ERR!   peer @aws-cdk/aws-iam@"1.95.1" from @aws-cdk/aws-cloudwatch@1.95.1
npm ERR!   node_modules/@aws-cdk/aws-cloudwatch
npm ERR!     peer @aws-cdk/aws-cloudwatch@"1.95.1" from @aws-cdk/aws-ec2@1.95.1
npm ERR!     node_modules/@aws-cdk/aws-ec2
npm ERR!       @aws-cdk/aws-ec2@"*" 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 /home/sean/.npm/eresolve-report.txt for a full report.

--force 选项听起来并不理想。应该怎么做才能解决上游依赖冲突?我知道 AWS CDK 在核心库和构造库之间匹配包版本时非常严格。

// project generated via $ cdk init app --language typescript
  "devDependencies": {
    "@aws-cdk/assert": "1.95.0",
    "@types/jest": "^26.0.10",
    "@types/node": "10.17.27",
    "aws-cdk": "1.95.0",
    "jest": "^26.4.2",
    "ts-jest": "^26.2.0",
    "ts-node": "^9.0.0",
    "typescript": "~3.9.7"
  },
  "dependencies": {
    "@aws-cdk/core": "1.95.0",
    "source-map-support": "^0.5.16"
  }

1 个答案:

答案 0 :(得分:3)

根据评论,安装与 aws-cdk 和 @aws-cdk/core 版本相同的依赖项解决了问题。

<块引用>

npm install @aws-cdk/aws-ec2@1.95.0