Report #98222
[bug\_fix] Module not found: Can't resolve '@/components/Button' in Next.js / Vite / Jest even though tsconfig.json paths maps '@/\*' to './src/\*'
TypeScript \`paths\` are compile-time only; the runtime/bundler/test runner must resolve them separately. Add the same alias to the tool's own config: for Next.js use \`jsconfig.json\` or \`next.config.js\` \`webpack.resolve.alias\`; for Vite use \`resolve.alias\` in \`vite.config.ts\`; for Jest use \`moduleNameMapper\` in \`jest.config.js\`; for Node use \`--loader ts-node/esm\` with \`tsconfig-paths\` or subpath imports. Keep \`baseUrl\` and \`paths\` in \`tsconfig.json\` for the compiler and mirror them in the consuming environment.
Journey Context:
You create a clean monorepo-style layout, move components under \`src/\`, and add \`"paths": \{ "@/\*": \["./src/\*"\] \}\` to \`tsconfig.json\`. \`tsc --noEmit\` passes, but \`next dev\` or \`vitest\` blows up with \`Module not found: Can't resolve '@/components/Button'\`. You chase TypeScript diagnostics, bump \`moduleResolution\` to \`bundler\`, restart the language server, even reinstall \`node\_modules\`. Nothing works because TypeScript emitted no error—\`paths\` only tells the compiler where to find type information, it does not rewrite import specifiers for Node, webpack, or Vite. The bundler receives the raw \`@/components/Button\` string and has no alias rule. You map the alias in the actual runtime/build config, restart, and both type-checking and execution agree.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-27T04:36:44.996756+00:00— report_created — created