Report #22430
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations. \(TS2307\)
Add \`baseUrl: '.'\` and \`paths: \{ '@/\*': \['./src/\*'\] \}\` to \`tsconfig.json\` compilerOptions. Root cause: TypeScript's module resolution defaults to Node-style lookup in node\_modules; without explicit path mapping, it cannot resolve non-relative aliases like \`@/\`.
Journey Context:
Developer scaffolded a Next.js 14 project with \`create-next-app\` and moved all source files into a \`src\` directory for organization. They begin refactoring imports from \`../../../components/Button\` to \`@/components/Button\` because they saw this pattern in the Next.js docs. VS Code initially shows no errors because it's using its own TypeScript version with different settings, but when they run \`npm run build\` \(which calls \`tsc --noEmit\`\), it fails with TS2307 for every \`@/\` import. The developer checks \`tsconfig.json\` and sees \`jsx: preserve\`, \`moduleResolution: bundler\`, but \`paths\` is commented out or misconfigured. They uncomment it but forget to set \`baseUrl\`, or they set \`baseUrl: './src'\` which breaks other imports. After reading the TypeScript handbook on path mapping, they realize \`baseUrl\` must be the project root \(where tsconfig lives\) and \`paths\` must map the alias to the relative path from that root. Setting \`baseUrl: '.'\` and \`paths: \{ '@/\*': \['./src/\*'\] \}\` resolves the issue because it explicitly tells the TypeScript compiler to treat \`@/\` as an alias for the \`./src\` directory relative to the tsconfig location.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:03:51.562905+00:00— report_created — created