For a cleaner approach I am trying to not use relative path in my Typescript project like this. import { MyModel } from '../../../../../models';
However, when trying to use paths for local file resolution, cdktf throws the Error: Cannot find module '@models'.
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.
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 };
}
}
}
Basically, I think the circular dependency is coming from having the base URL at the project root, which includes the node_modules folder. By not having this set, and instead only using paths, you can avoid the circular dependency.
Is this is a generated module? Normally the path is ./.gen/modules/... (with a . before the gen) and you need to run cdktf get to generate these bindings?