Reputation: 820
I am using AWS CDK TypeScript. I am trying to create an cognito userpool in cdk. But it is showing below warning at "this",
Argument of type 'this' is not assignable to parameter of type 'Construct'.
Type 'RegionalCognitoCreation' is not assignable to type 'Construct'.
Property 'onValidate' is protected but type 'Construct' is not a class derived from 'Construct'.ts(2345)
My code is like below,
import * as cdk from '@aws-cdk/core';
import { UserPool } from '@aws-cdk/aws-cognito'
export class CognitoCreation extends cdk.Construct {
constructor(scope: cdk.Construct, id: string) {
super(scope, id);
new UserPool(this, 'myuserpool', {
userPoolName: 'my-userpool',
});
}
}
My package.jso looks like below,
{
"name": "******",
"version": "0.1.0",
"bin": {
"regional-infrastructure": "bin/*****.js"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "jest",
"cdk": "cdk"
},
"devDependencies": {
"@aws-cdk/assert": "1.53.0",
"@types/jest": "^25.2.1",
"@types/node": "10.17.5",
"jest": "^25.5.0",
"ts-jest": "^25.3.1",
"aws-cdk": "1.53.0",
"ts-node": "^8.1.0",
"typescript": "~3.7.2"
},
"dependencies": {
"@aws-cdk/aws-cloudformation": "^1.53.0",
"@aws-cdk/aws-cognito": "^1.54.0",
"@aws-cdk/aws-dynamodb": "^1.53.0",
"@aws-cdk/aws-elasticsearch": "^1.53.0",
"@aws-cdk/aws-iam": "^1.53.0",
"@aws-cdk/aws-lambda": "^1.53.0",
"@aws-cdk/aws-lambda-event-sources": "^1.53.0",
"@aws-cdk/aws-sns": "^1.53.0",
"@aws-cdk/aws-sns-subscriptions": "^1.53.0",
"@aws-cdk/core": "1.53.0",
"@aws-cdk/custom-resources": "^1.53.0",
"aws-sdk": "^2.716.0",
"source-map-support": "^0.5.16"
}
}
I have run "npm install" and cognito and other modules are added in node modules. I tried changing "this" with "scope" but that didn't worked for me. My cdk version is 1.46.0 (build 63860b2)
Upvotes: 0
Views: 3455
Reputation: 164
You've discovered a solution already, so I'm just posting this for posterity. The issue seems to come up a lot; I've dealt with it a number of times and it can be quite frustrating. The general advice is to delete node_modules, and re-install, making sure everything has matched versions. Be careful also if using a global install of the CDK and then calling it in the package.json. In that case you either need to remove the local install or run npx
before the cdk
command.
https://github.com/aws/aws-cdk/issues/7280
Upvotes: 4
Reputation: 820
There was some issue with my versions.
Making all versions of aws-cdk
and aws-*
the same solved the issue.
I did follow below steps:
Upvotes: 3