In the past, I encountered an issue with package.json
not being placed under rootDir
. Fortunately, I stumbled upon a helpful question on StackOverflow that addressed this exact problem. By following the recommendations provided in this answer, I managed to resolve that issue. However, my path aliases were still not recognized by tsc
when attempting to generate declaration files using tsc --build src
Note: Initially, I did not include declaration-specific properties like
"declaration": true
orin my"emitDeclarationOnly": true
tsconfig.json
because I was unable to transpile the code in the first place. My main focus at the moment is to get the path aliases working as they present a more complex and distinct issue compared to generating.d.ts
files. If this becomes problematic, I will address it later in a comment under the same issue.
Directory Structure:
.
├── src/
│ ├── helpers/
│ │ └── parseOptions.ts
│ ├── eswatch.ts
│ └── tsconfig.json
├── package.json
└── tsconfig.json
./tsconfig.json
{
"compilerOptions": {
"rootDir": ".",
"outDir": ".",
"resolveJsonModule": true,
"composite": true,
},
"files": ["package.json"],
}
./src/tsconfig.json
{
"compilerOptions": {
"rootDir": ".",
"outDir": "../types",
"resolveJsonModule": true
},
"paths": {
"@eswatch/*": ["./*"]
},
"references": [
{ "path": "../" }
]
}
The issue persists where path aliases are not functioning correctly when used with project references. Ideally, these aliases should work seamlessly, leading to the generation of declaration files.