Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument of type 'this' is not assignable to parameter of type 'Construct' #3416

Closed
karlbunnell opened this issue Jul 24, 2019 · 18 comments
Closed
Labels
needs-triage This issue or PR still needs to be triaged.

Comments

@karlbunnell
Copy link

I'm getting this same error while working through the AWS CDK Workshop.
Argument of type 'this' is not assignable to parameter of type 'Construct'.
Type 'HitCounter' is not assignable to type 'Construct'.
Types of property 'node' are incompatible.
Type 'import("/Users/dev_user/code/aws/cdk/cdk-workshop/node_modules/@aws-cdk/core/lib/construct").ConstructNode' is not assignable to type
'import("/Users/dev_user/code/aws/cdk/cdk-workshop/node_modules/@aws-cdk/aws-dynamodb/node_modules/@aws-cdk/core/lib/construct").ConstructNode'.
Types have separate declarations of a private property 'host'.ts(2345)

Following is the package.json
{
"name": "cdk-workshop",
"version": "0.1.0",
"bin": {
"cdk-workshop": "bin/cdk-workshop.js"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"cdk": "cdk"
},
"devDependencies": {
"@types/node": "8.10.45",
"typescript": "^3.3.3333",
"ts-node": "^8.1.0",
"aws-cdk": "^1.0.0"
},
"dependencies": {
"@aws-cdk/aws-apigateway": "^1.0.0",
"@aws-cdk/aws-dynamodb": "^1.1.0",
"@aws-cdk/aws-lambda": "^1.0.0",
"@aws-cdk/aws-sns": "^1.0.0",
"@aws-cdk/aws-sns-subscriptions": "^1.0.0",
"@aws-cdk/aws-sqs": "^1.0.0",
"@aws-cdk/core": "^1.0.0"
}
}

The type seems to be specified properly. This seems to be a bug.

@karlbunnell karlbunnell added the needs-triage This issue or PR still needs to be triaged. label Jul 24, 2019
@joshrp
Copy link
Contributor

joshrp commented Jul 25, 2019

I just ran in to this too and solved it. It's because your dependencies aren't aligned. You'll need the same version of all the CDK packages. Sometimes you can get away with it but it looks like there was a core change this time around and the Construct types now aren't compatible. 1.1.0 vs 1.0.0

"dependencies": {
  "@aws-cdk/aws-apigateway": "^1.0.0",
  "@aws-cdk/aws-dynamodb": "^1.1.0",
  "@aws-cdk/aws-lambda": "^1.0.0",
  "@aws-cdk/aws-sns": "^1.0.0",
  "@aws-cdk/aws-sns-subscriptions": "^1.0.0",
  "@aws-cdk/aws-sqs": "^1.0.0",
  "@aws-cdk/core": "^1.0.0"
}

npm update will take care of it without too much risk

@karlbunnell
Copy link
Author

Many thanks @joshrp! Your recommendation fixed it. Turns out I had "npm update" anytime I added a new aws CDK construct.

@xorai-chief
Copy link

tried npm update. Still have the same issue

@hoegertn
Copy link
Contributor

Please make sure all CDK dependencies have exactly the same version.

@aletheia
Copy link

I am having the same issue. My dependencies are at the same version 1.57.0

  "devDependencies": {
    "@aws-cdk/assert": "1.57.0",
    "@aws-cdk/aws-apigateway": "1.57.0",
    "@aws-cdk/aws-certificatemanager": "1.57.0",
    "@aws-cdk/aws-iam": "1.57.0",
    "@aws-cdk/aws-lambda": "1.57.0",
    "@aws-cdk/aws-lambda-nodejs": "^1.57.0",
    "@aws-cdk/aws-route53": "1.57.0",
    "@aws-cdk/aws-route53-targets": "1.57.0",
    "@aws-cdk/aws-s3": "1.57.0",
    "@aws-cdk/aws-s3-deployment": "1.57.0",
    "@istanbuljs/nyc-config-typescript": "1.0.1",
    "@types/chai": "4.2.12",
    "@types/js-yaml": "3.12.5",
    "@types/lodash.clone": "4.5.6",
    "@types/lodash.foreach": "4.5.6",
    "@types/lodash.merge": "4.6.6",
    "@types/lodash.omit": "4.5.6",
    "@types/mocha": "8.0.3",
    "@types/mongodb": "3.5.26",
    "@types/nanoid": "2.1.0",
    "@types/node": "14.6.0",
    "@types/node-fetch": "2.5.7",
    "@types/sinon": "9.0.4",
    "@types/sinon-chai": "3.2.4",
    "@typescript-eslint/eslint-plugin": "3.9.1",
    "@typescript-eslint/parser": "3.9.1",
    "aws-cdk": "1.57.0",
    "chai": "4.2.0",
    "eslint": "7.7.0",
    "eslint-config-google": "0.14.0",
    "eslint-config-prettier": "6.11.0",
    "eslint-plugin-mocha": "8.0.0",
    "gts": "2.0.2",
    "iam-policy-generator": "1.2.0",
    "mocha": "8.1.1",
    "nyc": "15.1.0",
    "sinon": "9.0.3",
    "sinon-chai": "3.5.0",
    "source-map-support": "0.5.19",
    "ts-clean": "1.0.3",
    "ts-node": "^8.10.2",
    "typescript": "3.9.7"
  },
  "dependencies": {
    "@aws-cdk/core": "1.57.0",
    "ajv": "6.12.4",
    "aws-sdk": "2.735.0",
    "global": "^4.4.0",
    "js-yaml": "3.14.0",
    "lodash.clone": "4.5.0",
    "lodash.foreach": "4.5.0",
    "lodash.merge": "4.6.2",
    "lodash.omit": "4.5.0",
    "mongodb": "3.6.0",
    "nanoid": "3.1.12",
    "node-fetch": "2.6.0",
    "winston": "3.3.3"
  },

I am stuck with no idea how to fix something that this morning was working well.

@hoegertn
Copy link
Contributor

Your aws-lambda-nodejs dependecy has a ^ so it uses the latest version.

@salmontecbsi
Copy link

Thanks guys. This post helped me get my issue resolved as well.

npm update -g

@fuzztooth
Copy link

As true today as it was then. This was the answer for me.

@NawwafHusain
Copy link

NawwafHusain commented May 23, 2022

I'm having a similar issue, error:
"const app: cdk.App
Argument of type 'App' is not assignable to parameter of type 'Construct'.
Types of property 'node' are incompatible.
Type 'ConstructNode' is missing the following properties from type 'Node': _locked, _children, _context, _metadata, and 6 more."

I'm following the exact steps defined in the aws start guild (https://aws.amazon.com/getting-started/guides/setup-cdk/module-three/). Initially I had issues importing @aws-cdk/core but ran npm install @aws-cdk/core and that fixed that but gave me the error motioned above. npm update or npm update -g does not solve the problem. my code (default code after running cdk init --language typescript) is linked and so are my dependencies from the 'package.json' file

#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from '@aws-cdk/core'
import { CdkDemoStack } from '../lib/cdk-demo-stack';

const app = new cdk.App();
new CdkDemoStack(app, 'CdkDemoStack', {
  /* If you don't specify 'env', this stack will be environment-agnostic.
   * Account/Region-dependent features and context lookups will not work,
   * but a single synthesized template can be deployed anywhere. */

  /* Uncomment the next line to specialize this stack for the AWS Account
   * and Region that are implied by the current CLI configuration. */
  // env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },

  /* Uncomment the next line if you know exactly what Account and Region you
   * want to deploy the stack to. */
  // env: { account: '123456789012', region: 'us-east-1' },

  /* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
});
{
  "name": "cdk-demo",
  "version": "0.1.0",
  "bin": {
    "cdk-demo": "bin/cdk-demo.js"
  },
  "scripts": {
    "build": "tsc",
    "watch": "tsc -w",
    "test": "jest",
    "cdk": "cdk"
  },
  "devDependencies": {
    "@types/jest": "^27.5.0",
    "@types/node": "10.17.27",
    "@types/prettier": "2.6.0",
    "aws-cdk": "^2.25.0",
    "jest": "^27.5.1",
    "ts-jest": "^27.1.4",
    "ts-node": "^10.7.0",
    "typescript": "~3.9.7"
  },
  "dependencies": {
    "@aws-cdk/core": "^1.157.0",
    "aws-cdk-lib": "2.25.0",
    "constructs": "^10.0.0",
    "source-map-support": "^0.5.21"
  }
}

EDIT: I found the solution on another issue raised by someone else following the getting started guild:
image
here's a link to the workshop mentioned in the screenshot: https://cdkworkshop.com/

@raikarjayani
Copy link

I am also having the same issue
For the line new eks.Cluster(this, ...), getting this error --> Argument of type 'undefined' is not assignable to parameter of type 'Construct'.ts(2345)

Here is my ts file

import { Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as eks from 'aws-cdk-lib/aws-eks';
import * as ec2 from 'aws-cdk-lib/aws-ec2';

export class AwsCdkStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);
  }
}

const newCluster = new eks.Cluster(this, 'Dbaas-eks-cluster_cdk', {
  version: eks.KubernetesVersion.V1_21,
  defaultCapacity: 5,
  defaultCapacityInstance: ec2.InstanceType.of(ec2.InstanceClass.M5, ec2.InstanceSize.SMALL),
});

Here is my package.json

{
  "name": "aws-cdk",
  "version": "0.1.0",
  "bin": {
    "aws-cdk": "bin/aws-cdk.js"
  },
  "scripts": {
    "build": "tsc",
    "watch": "tsc -w",
    "test": "jest",
    "cdk": "cdk"
  },
  "peerDependencies": {
    "aws-cdk-lib": "^2.8.0",
    "constructs": "^10.0.36"
  },
  "devDependencies": {
    "@aws-cdk/assert": "^2.8.0",
    "@aws-cdk/aws-appsync-alpha": "^2.8.0-alpha.0",
    "@types/jest": "^27.4.0",
    "@types/node": "^17.0.8",
    "aws-cdk-lib": "^2.8.0",
    "constructs": "^10.0.36",
    "esbuild": "^0.14.11",
    "jest": "^27.4.7",
    "ts-jest": "^27.0.2",
    "ts-node": "^10.4.0",
    "typescript": "^4.5.4"
  },
  "dependencies": {
    "@aws-cdk/aws-ec2": "^1.161.0",
    "@pulumi/aws": "^5.9.2",
    "@pulumi/awsx": "^0.40.0"
  }
}

@git-dwood
Copy link

I have the same issue as well. I've followed everything in this thread so far and still get the same result.

{
  "name": "cdk-workshop",
  "version": "0.1.0",
  "bin": {
    "cdk-workshop": "bin/cdk-workshop.js"
  },
  "scripts": {
    "build": "tsc",
    "watch": "tsc -w",
    "test": "jest",
    "cdk": "cdk"
  },
  "devDependencies": {
    "@aws-cdk/assert": "1.57.0",
    "@aws-cdk/aws-apigateway": "1.57.0",
    "@aws-cdk/aws-certificatemanager": "1.57.0",
    "@aws-cdk/aws-iam": "1.57.0",
    "@aws-cdk/aws-lambda": "1.57.0",
    "@aws-cdk/aws-lambda-nodejs": "^1.57.0",
    "@aws-cdk/aws-route53": "1.57.0",
    "@aws-cdk/aws-route53-targets": "1.57.0",
    "@aws-cdk/aws-s3": "1.57.0",
    "@aws-cdk/aws-s3-deployment": "1.57.0",
    "@istanbuljs/nyc-config-typescript": "1.0.1",
    "@types/chai": "4.2.12",
    "@types/js-yaml": "3.12.5",
    "@types/lodash.clone": "4.5.6",
    "@types/lodash.foreach": "4.5.6",
    "@types/lodash.merge": "4.6.6",
    "@types/lodash.omit": "4.5.6",
    "@types/mocha": "8.0.3",
    "@types/mongodb": "3.5.26",
    "@types/nanoid": "2.1.0",
    "@types/node": "14.6.0",
    "@types/node-fetch": "2.5.7",
    "@types/sinon": "9.0.4",
    "@types/sinon-chai": "3.2.4",
    "@typescript-eslint/eslint-plugin": "3.9.1",
    "@typescript-eslint/parser": "3.9.1",
    "aws-cdk": "1.57.0",
    "chai": "4.2.0",
    "eslint": "7.7.0",
    "eslint-config-google": "0.14.0",
    "eslint-config-prettier": "6.11.0",
    "eslint-plugin-mocha": "8.0.0",
    "gts": "2.0.2",
    "iam-policy-generator": "1.2.0",
    "mocha": "8.1.1",
    "nyc": "15.1.0",
    "sinon": "9.0.3",
    "sinon-chai": "3.5.0",
    "source-map-support": "0.5.19",
    "ts-clean": "1.0.3",
    "ts-node": "^8.10.2",
    "typescript": "3.9.7"
  },
  "dependencies": {
    "@aws-cdk/core": "1.57.0",
    "ajv": "6.12.4",
    "aws-sdk": "2.735.0",
    "global": "^4.4.0",
    "js-yaml": "3.14.0",
    "lodash.clone": "4.5.0",
    "lodash.foreach": "4.5.0",
    "lodash.merge": "4.6.2",
    "lodash.omit": "4.5.0",
    "mongodb": "3.6.0",
    "nanoid": "3.1.12",
    "node-fetch": "2.6.0",
    "winston": "3.3.3"
  }
}

import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as apigw from 'aws-cdk-lib/aws-apigateway';
import { HitCounter } from './hitcounter';
import { TableViewer } from 'cdk-dynamo-table-viewer';

export class CdkWorkshopStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const hello = new lambda.Function(this, 'HelloHandler', {
      runtime: lambda.Runtime.NODEJS_14_X,
      code: lambda.Code.fromAsset('lambda'),
      handler: 'hello.handler'
    });

    const helloWithCounter = new HitCounter(this, 'HelloHitCounter', {
      downstream: hello
    });

    // defines an API Gateway REST API resource backed by our "hello" function.
    new apigw.LambdaRestApi(this, 'Endpoint', {
      handler: helloWithCounter.handler
    });
    new TableViewer(this, 'ViewHitCounter', {
      title: 'Hello Hits',
      table: //??????
    });
  }
}

@gmarshall56
Copy link

Sorry folks but this is still not working. I started with Natalia Marek's very good example and the cdk workshop specified earlier.

This is my package.json in my cdk-infra project:

image

You will notice that all@aws-cdk dependencies are all the same version, except for the aws-cdk-lib dependency which is the latest version published three days ago as of this writing.

You can see the compiler errors I am getting in VScode:

image

The compiler errors I am getting:

  • cdk.Stack: "Property 'Stack' does not exist on type 'typeof import.....
  • StackProps: "Namespace '"C:/Users/xxxxxx/VSCodeProjects/...."' has no exported member 'StackProps'.
  • this: "Argument of type 'this' is not assignable to parameter of type 'Construct'.
    Type 'CdkInfraStack' is missing the following properties from type 'Construct': onValidate, onPrepare, onSynthesizets(2345)

....So I'm at a loss here. I don't know how to fix this. Every version of a ts (or js) file of cdk...stack file I try I keep getting compiler errors of one type or another.

Thank you.

@aletheia
Copy link

aletheia commented Aug 21, 2022 via email

@SabrinaKaren
Copy link

Sorry folks but this is still not working. I started with Natalia Marek's very good example and the cdk workshop specified earlier.

This is my package.json in my cdk-infra project:

image

You will notice that all@aws-cdk dependencies are all the same version, except for the aws-cdk-lib dependency which is the latest version published three days ago as of this writing.

You can see the compiler errors I am getting in VScode:

image

The compiler errors I am getting:

  • cdk.Stack: "Property 'Stack' does not exist on type 'typeof import.....
  • StackProps: "Namespace '"C:/Users/xxxxxx/VSCodeProjects/...."' has no exported member 'StackProps'.
  • this: "Argument of type 'this' is not assignable to parameter of type 'Construct'.
    Type 'CdkInfraStack' is missing the following properties from type 'Construct': onValidate, onPrepare, onSynthesizets(2345)

....So I'm at a loss here. I don't know how to fix this. Every version of a ts (or js) file of cdk...stack file I try I keep getting compiler errors of one type or another.

Thank you.

@gmarshall56 I understand you perfectly. I'm also experiencing these incompatibilities. Did you find any solution?

@gchantzialexiou
Copy link

@SabrinaKaren probably you already solved this by now but:

aws-cdk-lib is CDK v2 modules and @aws-cdk/core is v1, you should use V2 instead. You can't combine V1 and V2 modules.

convert all your @aws-cdk to V2

Hope that helps

@abarbosa-godaddy
Copy link

Same here. All the versions are the same but I get the same error.

  "devDependencies": {
    "@aws-cdk/assert": "1.148.0",
    "@aws-sdk/client-dynamodb": "^3.58.0",
    "@aws-sdk/client-ssm": "^3.58.0",
    "@shelf/jest-dynamodb": "^2.1.0",
    "@types/graphql": "^14.5.0",
    "@types/graphql-fields": "^1.3.4",
    "@types/jest": "^26.0.10",
    "@types/lodash": "^4.14.181",
    "@types/luxon": "^2.3.1",
    "@types/node": "10.17.27",
    "@types/node-fetch": "^3.0.3",
    "@typescript-eslint/eslint-plugin": "^4.33.0",
    "@typescript-eslint/parser": "^4.33.0",
    "aws-cdk": "1.148.0",
    "eslint": "^7.32.0",
    "eslint-config-prettier": "^8.5.0",
    "jest": "^26.4.2",
    "node-fetch": "^3.2.3",
    "npm-run-all": "^4.1.5",
    "ts-jest": "^26.2.0",
    "ts-node": "^9.0.0",
    "typescript": "^4.6.3"
  },
  "dependencies": {
    "@apidevtools/swagger-parser": "^10.0.3",
    "@aws-cdk/aws-ssm": "1.148.0",
    "@aws-cdk/cloud-assembly-schema": "1.148.0",
    "@aws-cdk/core": "1.148.0",
    "@aws-cdk/cx-api": "1.148.0",
    "@aws-sdk/client-acm": "^3.58.0",
    "@babel/runtime": "^7.17.8",
    "@elastic/ecs-winston-format": "^1.3.1",
    "@wsb/gd-service-catalog": "^4.0.11",
    "aws-sdk": "^2.1104.0",
    "lodash": "^4.17.21",
    "luxon": "^2.3.1",
    "openapi-types": "^9.3.0",
    "redis": "^4.0.4",
    "source-map-support": "^0.5.16",
    "winston": "^3.6.0",
    "yaml": "^1.10.2"
  }

@daryasary
Copy link

@gchantzialexiou
I have the same issue as mentioned and didn't understand your solution.

currently latest version of @aws-cdk/aws-lambda-event-sources is 1.202.0 and for aws-cdk-lib is 2.80.0.

How can I upgrade @aws-cdk/aws-lambda-event-sources or @aws-cdk/aws-secretsmanager into v2?

Obviously npm update is not working here.

@lsdeva
Copy link

lsdeva commented Sep 21, 2023

Could lousy import declarations cause this symptom?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests