我有由cdk cli(Typecript Language)生成的代码:
import { Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as appsync from '@aws-cdk/aws-appsync';
export class BookStoreGraphqlApiStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const api = new appsync.GraphqlApi(this, 'MyApi', {
name: 'my-book-api',
schema: appsync.Schema.fromAsset('graphql/schema.graphql')
});
}
}我得到了一个错误:
Argument of type 'this' is not assignable to parameter of type 'Construct'.
Type 'BookStoreGraphqlApiStack' is missing the following properties from type 'Construct': onValidate, onPrepare, onSynthesize我的package.json:
"devDependencies": {
"@types/jest": "^26.0.10",
"@types/node": "10.17.27",
"aws-cdk": "2.2.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.136.0",
"aws-cdk-lib": "2.2.0",
"constructs": "^10.0.12",
"source-map-support": "^0.5.16"
}节点版本: v16.13.0
aws版本: 2.2.0
发布于 2021-12-19 19:06:39
您正在混合来自CDK V1和新发布的CDK V2的依赖关系,它们是不兼容的。
若要获得有效的V2设置,请将AppSync包更改为import * as appsync from '@aws-cdk/aws-appsync-alpha'。在V2中,alpha API有独立的包,稳定的包位于公共的aws-cdk-lib中。AppSync的L2结构属于alpha类别。
以下是两个CDK版本的导入模式概述:
// V2
import { Construct } from 'constructs'; // construct is in a separate package
import { Stack, StackProps, aws_s3 as s3 } from 'aws-cdk-lib'; // common package for stable construct
import * as appsync from '@aws-cdk/aws-appsync-alpha' // alpha constructs in separate packages
// V1 - separate packages core and for each service
import * as cdk from '@aws-cdk/core';
import * as appsync from '@aws-cdk/aws-appsync';发布于 2021-12-19 19:05:38
原来这是aws的一个已知问题,因为v2没有正确迁移,解决方案是:
npm un -g aws-cdknpm i -g aws-cdk@1.136.0https://stackoverflow.com/questions/70411255
复制相似问题