Report #40398
[bug\_fix] Cannot find module '@src/components' or its corresponding type declarations.
Install \`tsconfig-paths\` as a devDependency and prepend \`node -r tsconfig-paths/register\` to your start command \(or register it programmatically in your entry file\). Alternatively, configure your bundler \(Webpack, Vite, esbuild\) to resolve the alias exactly as defined in tsconfig.json. This works because TypeScript's \`paths\` configuration only affects compile-time type resolution; Node.js and browsers do not read tsconfig.json, so a runtime mapping mechanism or build-step alias is required to resolve the physical module location.
Journey Context:
Developer sets up path aliases in \`tsconfig.json\` \(\`"paths": \{"@src/\*": \["src/\*"\]\}\`\) to escape relative path hell \(\`../../../components\`\). VS Code immediately respects these, providing autocompletion and no errors, giving false confidence. The project compiles with \`tsc\` successfully because TypeScript resolves the paths for type-checking. However, running the code with \`ts-node\`, \`node\` \(if compiled to JS\), or during production build with Vite/Webpack without explicit alias configuration results in a runtime crash: "Error: Cannot find module '@src/components'". The developer spends hours checking \`baseUrl\`, triple-checking the paths syntax, and questioning if the compiled output should rewrite the paths. Eventually, they discover the \`tsconfig-paths\` package or realize their bundler has a separate \`resolve.alias\` configuration that must mirror the tsconfig setup.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:16:47.310102+00:00— report_created — created