question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TS - Argument of type 'this' is not assignable to parameter of type 'Construct'

See original GitHub issue

I have a created a simple Stack that creates a VPC with three simple subnets. though I receive the error Argument of type ‘this’ is not assignable to parameter of type ‘Construct’ . When I use any other resource like S3 or SQS I do not receive the error. As of now, it happens only with VpcNetwork. The typescript code is as follows

cdk version: 0.8.0 (build bb95676) node version: 10.3.0

import * as cdk from '@aws-cdk/cdk'
import { VpcNetwork, SubnetType } from '@aws-cdk/aws-ec2'

class MyStack extends cdk.Stack {
    constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
        super(parent, name, props);

        new VpcNetwork(this, 'MyVPC', {
            cidr: '10.0.0.0/21',
            subnetConfiguration: [
              {
                cidrMask: 24,
                name: 'Ingress',
                subnetType: SubnetType.Public,
                natGateway: true,
              },
              {
                cidrMask: 24,
                name: 'Application',
                subnetType: SubnetType.Private,
              },
              {
                cidrMask: 28,
                name: 'Database',
                subnetType: SubnetType.Isolated,
              }
            ],
        });
    }
}

const app = new cdk.App(process.argv);
new MyStack(app, 'MyStack');
process.stdout.write(app.run());

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:38 (10 by maintainers)

github_iconTop GitHub Comments

75reactions
eladbcommented, Dec 24, 2018

Hi @benswinburne, I believe this is caused by the fact that your package.json file has mixed versions of the CDK (@aws-cdk/cdk is at 0.20.0 and @aws-cdk/aws-* are at 0.21.0):

{
  "dependencies": {
    "@aws-cdk/aws-ec2": "^0.21.0",
    "@aws-cdk/aws-ecs": "^0.21.0",
    "@aws-cdk/cdk": "^0.20.0"
  }
}

Try to upgrade everything to 0.21.0 and let us know if the issue still persists.

21reactions
eladbcommented, Aug 28, 2019

As mentioned above, this is usually caused by having more than a single version of the CDK in your node modules.

  1. Make sure your package.json lists the same version.
  2. Nuke node_modules
  3. Run npm install again
Read more comments on GitHub >

github_iconTop Results From Across the Web

Argument of type 'this' not assignable to parameter 'Construct'
The construct definition looks right to me. That error can occur if the various cdk modules aren't all at the same version; see...
Read more >
'this' is not assignable to parameter of type 'Construct' in CDK
I was working on one of my AWS-CDK apps in Typescript when I got squiggly lines under every 'this' in my code.
Read more >
Argument of type Not Assignable to type Construct in AWS CDK
The reason we get the "Argument of type is not assignable to parameter of type Construct" error in CDK is because we have...
Read more >
How to fix the Error Argument of type 'this' is not ... - WP-kyoto
Failed the npm run build command with the Argument of type 'this' is not assignable to parameter of type 'Construct' error. Why I...
Read more >
Argument of type is not assignable to parameter of ... - YouTube
Node js tutorial for Beginners. Argument of type is not assignable to parameter of type typescript | QueryDeepPartialEntity typeorm.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found