We have a codebase setup like so:
-A
--utils
---index.ts
--index.ts
--tsconfig.json
-B
--utils
---index.ts
--index.ts
--tsconfig.json
-tsconfig.json
Our root tsconfig.json contains the following:
"paths": {
"A/*": ["A/*"],
"B/*": ["B/*"],
},
Each package's tsconfig.json contains the following:
"paths": {
"utils/*": ["./utils/*"],
},
This works for our current purposes, since we currently only use TS for type checking but we actually generate builds with Babel, which has a similar setup in the alias property of the various .babelrc files.
We are looking to start running code using ts-node (or an equivalent) and have run into the issue that at runtime, TS has no idea how to resolve modules. For example:
// A/index.ts
import { someUtil } from 'utils'
export const someFunc() => someUtil();
// B/index.ts
import { someFunc } from 'A';
When we run npx ts-node ./B/index.ts we get an error saying `Cannot find modules 'utils'.
We know that we can get this working by hoisting everything to the root tsconfig.json, but it seems superfluous to have to import { someUtil } from 'A/utils when you are already in package A.
Is there a way to use paths in the manner that we have? We have also read a bit about project references and tried that but it didn't seem to get us anywhere.