Report #5795
[bug\_fix] error TS2307: Cannot find module '@app/components' or its corresponding type declarations.
Add the mapped directory to the \`include\` array in tsconfig.json \(e.g., \`"include": \["src/\*\*/\*", "packages/\*\*/\*"\]\`\), or if using project references, ensure \`composite: true\` is set in the referenced package's tsconfig. The root cause is that \`paths\` only maps import specifiers to file paths, but TypeScript only considers files matching the \`include\`, \`files\`, or project reference patterns as part of the compilation context. If the target of a path mapping falls outside the included file set, TypeScript cannot resolve the module.
Journey Context:
Developer sets up a monorepo with Yarn workspaces and configures path mapping in the root tsconfig.json: \`"paths": \{ "@app/\*": \["packages/\*"\] \}\`. VS Code intellisense works perfectly, showing autocomplete for \`import \{ Button \} from '@app/components'\`. However, running \`tsc\` or building with Vite fails with TS2307. Developer checks that \`packages/components/index.ts\` exists and exports the component. They add \`baseUrl: "."\` and verify the path mapping syntax. They enable \`traceResolution: true\` in tsconfig and see TypeScript searching in \`node\_modules/@app/components\` but never looking in \`packages/components\`. Realization strikes: the \`include\` array in tsconfig.json is set to \`\["src/\*\*/\*"\]\`, which excludes the \`packages\` directory. Even though \`paths\` tells TypeScript where to look, the files in \`packages\` are not considered part of the TypeScript project, so the compiler refuses to resolve them. Adding \`"packages/\*\*/\*"\` to \`include\` immediately resolves the issue.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T22:12:55.371807+00:00— report_created — created