Report #56258
[bug\_fix] Cannot find module 'X' or its corresponding type declarations when using path mapping
Ensure 'baseUrl' is set in tsconfig.json alongside 'paths', and if running the code \(not just compiling\), use a runtime loader like 'tsx' or 'ts-node' with 'tsconfig-paths/register' to resolve the aliases at runtime.
Journey Context:
A developer scaffolding a new Next.js project sets up path aliases in tsconfig.json: 'paths': \{ '@/\*': \['./\*'\] \}. Imports like 'import \{ Button \} from '@/components/Button'' work perfectly in VS Code with IntelliSense, and 'Go to Definition' jumps to the right file. However, running 'tsc --noEmit' throws 'Cannot find module '@/components/Button'' or its corresponding type declarations. The developer checks 'baseUrl' and realizes it was missing; they add 'baseUrl': '.'. The tsc error persists. They search online and realize that 'paths' is only honored by the TypeScript compiler for type-checking, but Node.js runtime \(or even tsc emitting to outDir\) doesn't know how to resolve these aliases without additional configuration. They switch to using 'tsx' for development which automatically respects tsconfig paths, or they add 'tsconfig-paths/register' to their node start script. The root cause was conflating compile-time path resolution with runtime module resolution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T00:55:23.795790+00:00— report_created — created