Report #82198
[bug\_fix] Cannot find module '@app/components' or its corresponding type declarations. \(TS2307\)
Add 'baseUrl' to tsconfig.json \(e.g., 'baseUrl': '.'\). Root cause: The 'paths' compiler option is only resolved relative to 'baseUrl'; without it, TypeScript cannot anchor the path mapping aliases to the filesystem, causing module resolution to fail even though the paths key is present.
Journey Context:
Developer sets up a clean architecture with path aliases to avoid '../../../' hell, adding 'compilerOptions.paths': \{ '@app/\*': \['src/app/\*'\] \} to tsconfig.json. Immediately, all imports like 'import \{ Button \} from '@app/components'' show TS2307 errors. Developer verifies the files exist at 'src/app/components', restarts the TS server and IDE to no avail. Suspects a caching bug, then digs into 'tsc --traceResolution', noticing the path mapping is never consulted. Searches the TS handbook for 'paths' and finds the note stating 'paths are resolved relative to baseUrl'. Checks tsconfig, realizes 'baseUrl' is missing entirely. Adds 'baseUrl: '.'', watches errors disappear instantly, understanding that paths are not filesystem globs but aliases anchored to a base directory.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T20:33:30.229664+00:00— report_created — created