0

I have my companies own say @mycompany/cdk": "^1.11.11" (used to manage context environment) which worked with CDK v1, now while using CDK v2 we are facing the error so want to know is it possible to work with CDK v2 and what should we do without touching "mycompany/cdk"

Following error:

ashishkarpe in ~/code/metrics-service/deploy/cdk on branch > cdk ls
npx: installed 217 in 4.275s
⨯ Unable to compile TypeScript:
lib/cdk-stack.ts:31:24 - error TS2345: Argument of type 'mycompanyStackProps<ICdkStackProps>' is not assignable to parameter of type 'StackProps'.
  Types of property 'synthesizer' are incompatible.
    Type 'import("/Users/ashishkarpe/code/metrics-service/deploy/cdk/node_modules/mycompany/cdk/node_modules/@aws-cdk/core/lib/stack-synthesizers/types").IStackSynthesizer | undefined' is not assignable to type 'import("/Users/ashishkarpe/code/metrics-service/deploy/cdk/node_modules/@aws-cdk/core/lib/stack-synthesizers/types").IStackSynthesizer | undefined'.
      Type 'import("/Users/ashishkarpe/code/metrics-service/deploy/cdk/node_modules/@mycompany/cdk/node_modules/@aws-cdk/core/lib/stack-synthesizers/types").IStackSynthesizer' is not assignable to type 'import("/Users/ashishkarpe/code/metrics-service/deploy/cdk/node_modules/@aws-cdk/core/lib/stack-synthesizers/types").IStackSynthesizer'.
        Types of property 'bind' are incompatible.
          Type '(stack: import("/Users/ashishkarpe/code/metrics-service/deploy/cdk/node_modules/@mycompany/cdk/node_modules/@aws-cdk/core/lib/stack").Stack) => void' is not assignable to type '(stack: import("/Users/ashishkarpe/code/metrics-service/deploy/cdk/node_modules/@aws-cdk/core/lib/stack").Stack) => void'.
            Types of parameters 'stack' and 'stack' are incompatible.
              Type 'import("/Users/ashishkarpe/code/metrics-service/deploy/cdk/node_modules/@aws-cdk/core/lib/stack").Stack' is not assignable to type 'import("/Users/ashishkarpe/code/metrics-service/deploy/cdk/node_modules/@mycompany/cdk/node_modules/@aws-cdk/core/lib/stack").Stack'.
                Types of property 'tags' are incompatible.
                  Type 'import("/Users/ashishkarpe/code/metrics-service/deploy/cdk/node_modules/@aws-cdk/core/lib/tag-manager").TagManager' is not assignable to type 'import("/Users/ashishkarpe/code/metrics-service/deploy/cdk/node_modules/@mycompany/cdk/node_modules/@aws-cdk/core/lib/tag-manager").TagManager'.
                    Types have separate declarations of a private property 'tags'.

31       super(scope, id, props);
                          ~~~~~

Subprocess exited with error 1

My package.json:

{
  "name": "deploy",
  "version": "2",
  "bin": {
    "deploy": "bin/deploy.js"
  },
  "scripts": {
    "build": "tsc",
    "watch": "tsc -w",
    "test": "jest",
    "cdk": "cdk"
  },
  "devDependencies": {
    "@types/jest": "^26.0.10",
    "@types/node": "^17.0.18",
    "aws-cdk": "^2.12.0",
    "jest": "^26.4.2",
    "ts-jest": "^26.2.0",
    "ts-node": "^9.0.0",
    "typescript": "^3.9.10"
  },
  "dependencies": {
    "@aws-cdk/aws-glue-alpha": "^2.13.0-alpha.0",
    "@aws-cdk/aws-kinesisfirehose-alpha": "^2.13.0-alpha.0",
    "@aws-cdk/aws-kinesisfirehose-destinations-alpha": "^2.13.0-alpha.0",
    "@aws-cdk/core": "^2.13.0",
    "@mycompany/cdk": "^1.11.11",
    "athena-express": "^7.1.4",
    "aws-cdk-lib": "^2.13.0",
    "aws-sdk": "^2.1069.0",
    "constructs": "^10.0.0",
    "dotenv": "^16.0.0",
    "npm": "^5.10.0",
    "source-map-support": "^0.5.16",
    "with": "^7.0.2"
  }
}

Update1 : I have ran following command:

alias cdk1="npx aws-cdk@1.x"
alias cdk="npx aws-cdk@2.x"

ashishkarpe in ~/code/metrics-service/deploy/cdk on branch add-apikey > cdk --version
npx: installed 217 in 5.862s
2.13.0 (build b0b744d)
ashishkarpe in ~/code/metrics-service/deploy/cdk on branch add-apikey > cdk1 --version
npx: installed 217 in 4.376s
1.145.0 (build 9f96380)
ashishkarpe in ~/code/metrics-service/deploy/cdk on branch add-apikey > cdk1 ls ==> **gives same error**
Ashish Karpe
  • 5,087
  • 7
  • 41
  • 66

1 Answers1

1

You are mixing dependencies from CDK V1 and the newly released CDK V2, which are incompatible. https://docs.aws.amazon.com/cdk/v2/guide/migrating-v2.html

Turns out this is a known problem with aws-cdk, since v2 isn't properly migrated, the solution is:

npm un -g aws-cdk
npm i -g aws-cdk@1.136.0
Eduard
  • 311
  • 1
  • 4