【问题标题】:Class constructor Construct cannot be invoked without 'new' - aws cdk没有“新”就不能调用类构造函数构造 - aws cdk
【发布时间】:2020-11-22 12:01:13
【问题描述】:

我在这里有一个 NPM 库,将用于多个 CDK 应用程序和 AWS 账户

export class FrontendConstruct extends Construct {
  constructor(parent: Construct, id: string, props: FrontendConstructProps) {
    super(parent, id);

//creating s3 bucket etc
//create cloudfront cdn

这是我在使用它的 cdk 应用程序上的堆栈

import * as ssFE from '@customnpmlibrary/cdk-ss-fe'

export interface stFrontendStackProps extends cdk.StackProps {
  /**
   * The domain name for the site to use
   */
  readonly domainName: string;
  /**
 * Location of FE code to deploy
 */
  readonly deploymentSource: string;
}

export class stFrontendStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props: stFrontendStackProps) {
    super(scope, id,props);

    new ssFE.FrontendConstruct 
      (this, 'stfeStack', {
      domainname: props.domainName,
      deploymentSource: props.deploymentSource
    });
  
  }
}

并创建应用程序

import { stFrontendStack } from '../lib/st-frontend-stack';

const app = new cdk.App();

new stFrontendStack(app, 'stFrontend-DEV', {
  env: {
    account: '1234',
    region: 'us-east-1'
  },
  domainName: 'url.url.com',
  deploymentSource:'../dist/stfe'
});

当我去部署它时,我得到了这个:在 cdk 合成器期间

Class constructor Construct cannot be invoked without 'new'

有什么想法或帮助吗?

【问题讨论】:

    标签: typescript aws-cdk


    【解决方案1】:

    这里的问题在于您的 ECMAScript 版本。这可以通过在 tsconfig.json 中使用 ES2018 来解决,如下所示:

    {
      "compilerOptions": {
        "target":"ES2018",
        "module": "commonjs",
        "lib": ["es2018"],
        ... any other options ...
      }
    }
    

    另外,我在使用参数运行tsc 时遇到了问题。您需要确保tsc 正确地选择了tsconfig.json。对我来说,从tsc 中删除参数解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2017-09-29
      • 2018-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-12
      • 2019-04-21
      • 2021-05-17
      相关资源
      最近更新 更多