question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[monocdk] Unable to create custom stacks that extend Stack

See original GitHub issue

When 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
riteshcommented, Sep 2, 2021

@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 the tsconfig.json over.

2reactions
blimmercommented, Dec 18, 2020

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 using tsdx to bundle. By default, it bundles for a web target, which was not exposing true Javascript classes in the output.

To fix it, I needed to use tsdx build --target node. Hopefully this helps someone else!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found