Resolving MODULE_NOT_FOUND Error for Internal Modules with TypeScript Path Aliases in AWS CDK during synthesis/deploymentt

I’m working on an AWS CDK project using TypeScript and encountering an issue with module resolution when running cdk synth or cdk deploy (the build is successful). My project structure includes internal modules that I’m trying to import into my CDK stacks, but I receive a MODULE_NOT_FOUND error during synthesis/deployment.

project structure

tsconfig.json

stack.ts

constant.ts

error message

Attempts to Resolve:

  1. I’ve verified the file paths and made sure that constant.ts exists at the specified location.
  2. I’ve tried using both relative(../common/type/constant) and absolute import (common/model/constant) paths.
  3. Running tsc directly compiles without any issues, but cdk synth or cdk deploy throws the error.
  4. I’ve also tried clearing node_modules and reinstalling, with no success.

I suspect the issue might be related to how the CDK CLI handles TypeScript path aliases or possibly how my TypeScript project is configured. However, I’m not sure how to diagnose or fix the issue to allow my CDK application to correctly resolve and import these internal modules.

Questions:

  1. How can I adjust my TypeScript or CDK configuration to resolve this issue?
  2. Is there a step I’m missing in the process to ensure the CDK CLI can handle TypeScript path aliases correctly?
  3. Are there known limitations or considerations with the AWS CDK and TypeScript imports that I should be aware of?
  4. Any guidance, diagnostic tips, or insights into how the AWS CDK and TypeScript work together in this context would be greatly appreciated.