Report #51941
[bug\_fix] Cannot find module '@/utils' or its corresponding type declarations. \(TS2307\)
Ensure 'baseUrl' is set \(e.g., '.'\) and that 'paths' mappings are relative to 'baseUrl', not 'rootDir'. If 'rootDir' is specified, remove it or adjust the path alias to account for the effective root. Verify 'moduleResolution' is set to 'node' or 'bundler', not 'classic'.
Journey Context:
Developer configures path aliases in tsconfig.json to avoid relative import hell: 'paths': \{'@/\*': \['./src/\*'\]\}'. VSCode IntelliSense works perfectly, showing no errors. However, running 'tsc' or building with Vite/Next.js throws 'Cannot find module '@/utils'...'. Developer tries adding 'baseUrl': '.', still fails. They check 'include' and 'exclude', even clearing 'rootDir'. The 'aha' moment comes when realizing 'rootDir' being set to './src' causes the path '@/\*' to resolve to './src/src/\*', or that 'moduleResolution' was implicitly 'classic' due to an old config template. Removing 'rootDir' or adjusting the path mapping to resolve relative to the config file location fixes it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T17:40:30.524054+00:00— report_created — created