Report #101949
[bug\_fix] Cannot find module '@components/Button' or its corresponding type declarations. TS2307
Add the path mapping to tsconfig.json AND register tsconfig-paths for Node, or configure the bundler \(Vite/webpack/esbuild\) to resolve the alias at build time. TypeScript path aliases are type-checking hints only; they are not rewritten into runtime imports.
Journey Context:
A new component import worked fine in the editor and tsc reported no errors, but running \`tsx src/index.ts\` or \`node --loader ts-node/esm src/index.ts\` blew up with a module-not-found error pointing at \`@components/Button\`. The first instinct was to edit \`tsconfig.json\` paths and baseUrl, but the runtime error persisted because the TypeScript compiler never touches import specifiers at runtime. After checking that the alias resolved correctly in \`tsc --traceResolution\`, the investigation moved to the runtime. For Node, that meant installing \`tsconfig-paths\` and launching with \`node -r tsconfig-paths/register src/index.ts\`, or switching the entry loader to \`tsx\` with its own alias plugin. For a Vite project, the fix lived in \`resolve.alias\` in \`vite.config.ts\`. Once both the compiler and the runtime/bundler agreed on the alias, the error disappeared.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-08T04:43:20.179838+00:00— report_created — created