Hi everyone. I'm working on a monolithic repo comp...
# general
w
Hi everyone. I'm working on a monolithic repo composed of microstacks written in typescript (see folder hierarchy in thread). I'm trying to use path aliases to avoid extensive
../../../
in my imports, so that I can refer to all my
lib
files using an alias from all of my stacks. I've defined the paths in the
tsconfig.json
file in the root of the repository, and have additionally referred to this using
extends
in a
tsconfig.json
file in each stack folder. The aliases aren't resolving, so I'm getting
Cannot find module
. Is this kind of thing supported currently?
Copy code
├── config
│   ├── base.template.yaml
│   └── localstack.template.yaml
├── lib
│   ├── components
│   │   └── aws
│   │       └── backend
│   │           └── S3KmsBackend.ts
│   └── utils
│       ├── Stack.ts
│       └── registerAutoTags.ts
├── stacks
│   └── stack-a
│       ├── Pulumi.yaml
│       ├── index.ts
│       └── package.json
│       └── tsconfig.json
│   └── stack-b
│       ├── Pulumi.yaml
│       ├── index.ts
│       └── package.json
│       └── tsconfig.json
├── tests
│   ├── docker-compose.e2e.yml
│   ├── e2e
│   │   └── e2e.test.ts
│   ├── tsconfig.json
│   ├── unit
│   │   └── lib
│   │       ├── components
│   │       │   └── aws
│   │       │       └── backend
│   │       │           └── S3KmsBackend.test.ts
│   │       └── utils
│   │           └── Stack.test.ts
│   └── utils
│       ├── captureConsole.ts
│       ├── env.ts
│       └── s3Helper.ts
├── tsconfig.json
├── package.json
├── requirements.txt
├── Pulumi.yaml
├── README.md
l
Yes, but not with the default TS config. The solution depends on how you want to make it work. I use Yarn workspaces and ESM; the workspaces work automatically, I need to add this to get ESM working:
Copy code
runtime:
  name: nodejs
  options:
    nodeargs: "--loader ts-node/esm --no-warnings"
You can also get tsconfig's paths working. I've had it working in the past, but since we switched to Yarn2, I've migrated everything to use that, and the tsconfig settings aren't needed for that.
If I recall correctly, I figured out how to get paths working by first doing it without Pulumi, then adding Pulumi. There were probably nodeargs involved, but I don't remember, sorry.
Oh I just remembered that with Yarn2, if you want to use workspaces and Pulumi together, you do need to set
nodeLinker: node-modules
in your .yarnrc.yml
w
Nice, okay yeah I think I'm going to go for the yarn2 migration as well, been a while since I've dabbled in the TS / JS ecosystem. Thanks for the tips, this is promising!