Mono repo directory structure:
tsconfig.json
tsconfig-base.json
package.json
packages/node_modules/packageA/tsconfig.json
packages/node_modules/packageB/tsconfig.json
packages/node_modules/packageC/tsconfig.json
packageB is a dependency of packageA and packageC. Both packageA and packageC import functions, types and interfaces from packageB.
The root tsconfig.json has references to all packages in alphabetical order:
{
"files": [],
"references": [
{
"path": "./packages/node_modules/packageA"
},
{
"path": "./packages/node_modules/packageB"
},
{
"path": "./packages/node_modules/packageC"
}
]
}
The tsconfig-base.json contains the following:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"declarationMap": true,
"importHelpers": true,
"inlineSources": true,
"inlineSourceMap": true,
"strictNullChecks": true,
"noImplicitAny": false,
"incremental": true,
"noEmitOnError": true,
"baseUrl": "./",
"paths": {
"*": ["node_modules/*"]
}
},
"exclude": ["node_modules"]
}
packageA and packageC tsconfig.json:
{
"extends": "../../../tsconfig-base.json",
"compilerOptions": {
"jsx": "react",
"jsxFactory": "h",
"outDir": "./dist",
"baseUrl": "./"
},
"include": ["..."],
"references": [
{
"path": "../packageB"
}
]
}
packageC will find packageB exports and packageA will not.
There are three possible solutions for this:
-
Re-order the references in the root tsconfig.json so that packageB is listed before packageA. This is not documented.
-
Include a reference to packageB in packageA and packageC. The packageB tsconfig.json needs the now mandatory (tsc will complain if it's missing) composite property set to true.
-
Ignore Add prepend to the root tsconfig.json packageB reference. Does not work for outDir: microsoft/TypeScript#26565