Report #91991
[bug\_fix] Cannot find module '@app/core' or its corresponding type declarations - runtime module resolution failure despite tsconfig paths being configured
TypeScript path mapping only affects compile-time type resolution, not runtime module loading. For Node.js, install and register \`tsconfig-paths\` \(e.g., \`node -r tsconfig-paths/register dist/index.js\`\) to resolve the mappings at runtime. Alternatively, migrate to Node.js native subpath imports \(\`package.json\` "imports" field\) which TypeScript supports via \`moduleResolution: "NodeNext"\`, eliminating the need for external resolvers.
Journey Context:
You configure \`compilerOptions.paths\` in \`tsconfig.json\` to map \`@app/core\` to \`./src/core\`, enabling clean absolute imports. VS Code IntelliSense works perfectly and \`tsc --noEmit\` passes. However, running \`node dist/main.js\` immediately crashes with "Error: Cannot find module '@app/core'". You spend hours verifying path patterns, trying different \`baseUrl\` values, and checking if the compiled JS in \`dist/\` has the correct relative paths—it doesn't, as TS never rewrites import specifiers. You realize that Node.js knows nothing about \`tsconfig.json\`. Searching reveals that \`tsc\` only checks types; it doesn't bundle or rewrite paths for Node. You find the \`tsconfig-paths\` package, add \`tsconfig-paths/register\` to your startup script \(or use \`NODE\_OPTIONS='-r tsconfig-paths/register'\`\), and the runtime resolution works. Alternatively, you refactor to use Node.js subpath imports \(\`"imports": \{ "\#core": "./src/core.js" \}\` in package.json\) with corresponding TS paths, which works natively in modern Node without extra packages.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:59:49.327735+00:00— report_created — created