[monocdk] Unable to create custom stacks that extend Stack
See original GitHub issueWhen trying to synthesize a custom Stack (which extends Stack), I receive the below error:
“Class constructor Stack cannot be invoked without ‘new’”
Here is the erroneous sample code:
export class FooStack extends Stack {
constructor(construct: Construct) {
super(construct);
new MyCustomConstruct(construct, "test");
}
}
const app = new App();
const stack = new FooStack(app);
app.synth();
However if using the Stack directly it works just fine as per the below sample code:
const app = new App();
const stack = new Stack(app, "testStack");
new SecureBucket(stack, 'test');
app.synth();
I am using the Construct from monocdk, tried with the Construct from the constructs package however received a different error relating to cannot find children.
Reproduction Steps
export class FooStack extends Stack {
constructor(construct: Construct) {
super(construct);
new MyCustomConstruct(construct, "test");
}
}
const app = new App();
const stack = new FooStack(app);
app.synth();
What did you expect to happen?
Stack should syntesize.
What actually happened?
Class constructor Stack cannot be invoked without ‘new’
Environment
- CDK CLI Version : 1.71.0 (build 953bc25)
- Framework Version: “constructs”: “3.0.4”, “monocdk”: “1.69.0”
- Node.js Version: v14.14.0
- OS : OS/X Catalina
- Language (Version): Typescript 3.9.5
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
class Stack (construct) · AWS CDK
In the ProducerStack class, call this.exportValue(this.bucket.bucketName) . This will make sure the CloudFormation Export continues to exist while the ...
Read more >What are Constructs in AWS CDK - Complete Guide
Learn about what AWS CDK constructs are, the Different Levels of CDK Constructs, How to write your own Constructs - complete guide.
Read more >AWS CDK giving: Could Not determine ordering between
I was able to resolve the issue. I named every stacks stackName a unique one. for VPC : user-VPC-stack, etc and the build...
Read more >How to export and import stack output values in CDK?
In CloudFormation, to share information between stack, it is normal to export a stack's output values, other stacks that are in the same...
Read more >Infrastructure Tests with CDK
Below is the CDK snippet that creates the S3 bucket. ... import * as s3 from '@aws-cdk/aws-s3'; export class BucketStack extends cdk.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@blimmer thanks for sharing this! I ran into the same issue, but mine was due to a missing
tsconfig.json
. To resolve it, I created a new cdk project in a temporary directory and copied thetsconfig.json
over.In case someone else finds this issue searching for the
Class constructor Stack cannot be invoked without 'new'
error message, I ran into this problem with an internal, shared CDK library usingtsdx
to bundle. By default, it bundles for aweb
target, which was not exposing true Javascriptclass
es in the output.To fix it, I needed to use
tsdx build --target node
. Hopefully this helps someone else!