3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[AWS CDK]thisがエラーになる

Last updated at Posted at 2019-10-09

new s3.Bucket使用としたらthisがエラー(TS2345)になった。

cdk-stack.ts
import * as cdk from '@aws-cdk/core';
import * as s3 from '@aws-cdk/aws-s3';

export class CdkStack extends cdk.Stack {
    constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
        super(scope, id, props);

        // this ok
        const serviceName: string = this.node.tryGetContext("serviceName");

        // this error
        const originBucket = new s3.Bucket(this, `${serviceName}BucketId`, {
            bucketName: `${serviceName}-bucket`
        });
    };
}

解決策

package.json内でaws-cdkのバージョンが混合していると発生するエラーらしいのでバージョンを揃える

package.json
  "devDependencies": {
    "@aws-cdk/core": "^1.11.0",
    "@aws-cdk/aws-s3": "^1.12.0",
    "aws-cdk": "^1.11.0",
    "@types/node": "^12.7.11"
  }

package.json
  "devDependencies": {
    "@aws-cdk/core": "^1.12.0",
    "@aws-cdk/aws-s3": "^1.12.0",
    "aws-cdk": "^1.12.0",
    "@types/node": "^12.7.11"
  }

参考

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?