Report #84423
[bug\_fix] Project reference to 'shared' results in 'Cannot find module' or types resolving to 'any' despite successful build.
When using Project References \(\`composite: true\`\), the referencing project must consume the declaration files \(\`.d.ts\`\) emitted by the referenced project, not its source \`.ts\` files. Ensure \`declaration: true\` is set in the referenced project's \`tsconfig.json\`. Run \`tsc --build\` \(or \`tsc -b\`\) to generate the \`outDir\` containing \`.js\` and \`.d.ts\` files. Configure the referencing project's imports to point to the built output \(e.g., using \`paths\` mapping to \`../shared/dist/\*\`\) or ensure the \`reference\` path and \`prepend\` settings \(if applicable\) correctly locate the built artifacts. Do not import directly from \`../shared/src\`.
Journey Context:
You split a large codebase into two TypeScript projects: \`app\` and \`shared\`, using Project References to speed up compilation. In \`app\`, you add a reference: \`\{ "path": "../shared" \}\`. You try to import a type: \`import \{ User \} from '../shared/src/types'\`. TypeScript reports \`Cannot find module '../shared/src/types'\` or treats the import as \`any\`. You check \`shared/tsconfig.json\` and realize it lacks \`composite: true\` and \`declaration: true\`. You add them and run \`tsc --build\` in the \`shared\` directory. It creates \`shared/dist/types.d.ts\`. You change the import in \`app\` to \`../shared/dist/types\`. It works, but you worry about importing from \`dist\`. You try to use \`prepend\` but realize it's only for \`outFile\` concatenation. You eventually understand that Project References are designed for build orchestration: \`app\` depends on the \*built artifacts\* of \`shared\`, not its source. You configure \`paths\` in \`app/tsconfig.json\` to resolve \`@shared/\*\` to \`../shared/dist/\*\` and update the \`reference\` to ensure build order. You run \`tsc --build\` from the root, and both projects compile correctly with full type safety.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T00:17:45.107482+00:00— report_created — created