Class constructor Construct 不能在没有 'new' 的情况下被调用 - aws cdk
Class constructor Construct cannot be invoked without 'new' - aws cdk
我这里有一个 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 synth
Class constructor Construct cannot be invoked without 'new'
有什么想法或帮助吗?
此处的问题与您的 ECMAScript 版本有关。这可以通过在 tsconfig.json
中使用 ES2018 来解决,如下所示:
{
"compilerOptions": {
"target":"ES2018",
"module": "commonjs",
"lib": ["es2018"],
... any other options ...
}
}
此外,当 运行 tsc
带有参数时,我 运行 遇到了问题。您需要确保 tsc
正确拾取 tsconfig.json
。对我来说,从 tsc
中删除参数解决了这个问题。
当我的依赖项不是最新的时,这似乎发生在我身上。我通常会核爆我的 node_modules/ (rm -rf node_modules
) 并再次执行 npm install
。
我这里有一个 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 synth
Class constructor Construct cannot be invoked without 'new'
有什么想法或帮助吗?
此处的问题与您的 ECMAScript 版本有关。这可以通过在 tsconfig.json
中使用 ES2018 来解决,如下所示:
{
"compilerOptions": {
"target":"ES2018",
"module": "commonjs",
"lib": ["es2018"],
... any other options ...
}
}
此外,当 运行 tsc
带有参数时,我 运行 遇到了问题。您需要确保 tsc
正确拾取 tsconfig.json
。对我来说,从 tsc
中删除参数解决了这个问题。
当我的依赖项不是最新的时,这似乎发生在我身上。我通常会核爆我的 node_modules/ (rm -rf node_modules
) 并再次执行 npm install
。