Yes, I do get the same error. If my local imports are plain interfaces, it works fine such as @models
, but as soon as I add a complex type or class (which has cdktf imports
such as Construct or IAspect.ts) it throws the above error. I dont know what I am doing wrong. I am using the latest version of typescript, cdktf etc. Some kinda cyclic dependency might be causing this which I am struggling to find.
This is my folder structure,
libs
- helpers
- tag-aspect.ts
- models
- my-model.ts
- constructs
- my-vpc.ts
src
- environments
- core
- tgw-stack.ts --> imports { TagAddingAspect } from "@helpers" --> Throws above error.
main.ts --> calls the tgw-stack.ts
TagAspect code inside lib\helpers
import { IConstruct } from "constructs";
import { IAspect } from "cdktf";
// Not all constructs are taggable, so we need to filter it
type TaggableConstruct = IConstruct & {
tags?: { [key: string]: string };
tagsInput?: { [key: string]: string };
};
function isTaggableConstruct(x: IConstruct): x is TaggableConstruct {
return "tags" in x && "tagsInput" in x;
}
export class TagsAddingAspect implements IAspect {
constructor(private tagsToAdd: Record<string, string>) {}
// This method is called on every Construct within the specified scope (resources, data sources, etc.).
visit(node: IConstruct) {
if (isTaggableConstruct(node)) {
// We need to take the input value to not create a circular reference
const currentTags = node.tagsInput || {};
this.tagsToAdd["Name"] = node.node.id;
node.tags = { ...this.tagsToAdd, ...currentTags };
}
}
}