我有這個由 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-cdk 版本:2.2.0
uj5u.com熱心網友回復:
您正在混合來自 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';
uj5u.com熱心網友回復:
原來這是 aws-cdk 的一個已知問題,因為 v2 沒有正確遷移,解決方案是:
npm un -g aws-cdk
npm i -g aws-cdk@1.136.0
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/387148.html
標籤:节点.js 打字稿 图形 aws-cdk aws-appsync
上一篇:打字稿-物件的分組和求和陣列-將字串轉換為陣列的問題
下一篇:如何以角度自動更新API回應
