Stack Exchange
Argument of type 'this' is not assignable to parameter of type 'Construct'
I am having a hard time figuring out what is the issue here even though I have same versions of cdk dependencies.
const identityPool = new cognito.CfnIdentityPool(this, "IdentityPool", {
Argument of type 'this' is not assignable to parameter of type 'Construct'.
  Type 'MyStack' is not assignable to type 'Construct'.
    Types of property 'node' are incompatible.
      Type 'import("(**/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode' is not assignable to type 'import("**/node_modules/@aws-cdk/aws-appsync/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode'.
        Types have separate declarations of a private property 'host'.ts(2345)
        
      

"devDependencies": {
      "@aws-cdk/assert": "1.106.0",
      "@types/aws-lambda": "^8.10.76",
      "@types/aws-sdk": "^2.7.0",
      "@types/jest": "^26.0.10",
      "@types/node": "^15.6.1",
      "aws-cdk": "1.106.0",
      "jest": "^26.4.2",
      "ts-jest": "^26.2.0",
      "ts-node": "^9.0.0",
      "typescript": "~3.9.7"
  },
  "dependencies": {
      "@aws-cdk/aws-appsync": "^1.106.0",
      "@aws-cdk/aws-cognito": "^1.106.0",
      "@aws-cdk/aws-dynamodb": "^1.106.0",
      "@aws-cdk/aws-lambda": "^1.106.0",
      "@aws-cdk/aws-s3": "^1.106.0",
      "@aws-cdk/core": "1.106.0",
      "graphql-scalars": "^1.9.3",
      "source-map-support": "^0.5.16",
      "yaml": "^1.10.2"
  }
}

Reproduction Steps
import * as appsync from "@aws-cdk/aws-appsync";
import * as cognito from "@aws-cdk/aws-cognito";
import * as ddb from '@aws-cdk/aws-dynamodb';
import * as iam from "@aws-cdk/aws-iam";
import * as lambda from '@aws-cdk/aws-lambda';
import * as s3 from "@aws-cdk/aws-s3";
import * as cdk from "@aws-cdk/core";


export class MyStack extends cdk.Stack {
   private readonly stage: Stage;
   private readonly context: string;

  private namePrefix() {
    return `${this.stage}-${this.context}`;
  }

  constructor(scope: cdk.Construct, id: string, props: MyStackProps) {
    super(scope, id, props);
    this.stage = props.stage;
    this.context = props.context;
    
     const userPool = new cognito.UserPool(
      this,
      this.namePrefix() + "-user-pool",
      {
        userPoolName: this.namePrefix() + "-user-pool",
        selfSignUpEnabled: true,
        removalPolicy: cdk.RemovalPolicy.DESTROY,
        accountRecovery: cognito.AccountRecovery.PHONE_AND_EMAIL,
        userVerification: {
          emailStyle: cognito.VerificationEmailStyle.CODE,
        },
        autoVerify: {
          email: true,
        },
        standardAttributes: {
          email: {
            required: true,
            mutable: true,
          },
        },
      }
    );
       const userPoolClient = userPool.addClient(
      this.namePrefix() + "-user-pool-client",
      {
        userPoolClientName: this.namePrefix() + "-user-pool-client",
        oAuth: {
          flows: { authorizationCodeGrant: true, implicitCodeGrant : true },
          scopes: [cognito.OAuthScope.PROFILE],
          callbackUrls: ["http://localhost:4200/callback"],
        },
        authFlows : {
          userPassword : true,
          userSrp : true
        },
        supportedIdentityProviders: [
          cognito.UserPoolClientIdentityProvider.COGNITO,
        ],
      }
    );

   


    const identityPool = new cognito.CfnIdentityPool(this, "IdentityPool", {
      allowUnauthenticatedIdentities: false, // Don't allow unathenticated users
      cognitoIdentityProviders: [
        {
          clientId: userPoolClient.userPoolClientId,
          providerName: userPool.userPoolProviderName,
        },
      ],
    });
    
  }
 }


Environment

**CDK CLI Version  : 1.106.1
Node.js Version:  v16.2.0
**OS               : Ubuntu
Language (Version): Typescript(4.3.2)


Please include import statements at the top of the file. Looks like you have something messed up there based on this line: Type 'import("(**/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode' is not assignable to type 'import("**/node_modules/@aws-cdk/aws-appsync/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode'. The second one is a longer path.

I don't think so.

Did you try to make the last import the first one? Maybe typescript will look into that dependency first?

It looks like you're having two distinct versions of @aws-cdk/core library. First make sure it is the issue:
yarn why @aws-cdk/core
# or
npm why @aws-cdk/core

will show you all versions of @aws-cdk/core installed in your project and packages using them. If there is more than one version present use the common spell:
rm -rf node_modules

rm yarn.lock
yarn install
# or
rm package-lock.json
npm install

If that still doesn't help and there are still two versions of that package use yarn resolutions to force the single version resolution.
