Report #16873
[bug\_fix] Error: Cannot find module '@app/utils' or its corresponding type declarations. \(TS2307\) at runtime: MODULE\_NOT\_FOUND
Install \`tsconfig-paths\` and preload it \(\`node -r tsconfig-paths/register\`\), OR migrate to Node.js native subpath imports by defining an 'imports' field in package.json \(e.g., '"\#src/\*": "./src/\*"'\) and referencing '\#src/utils' in TypeScript, eliminating runtime path mapping dependencies.
Journey Context:
You set up 'paths': \{'@app/\*': \['./src/\*'\]\} in tsconfig to clean up deep relative imports. VS Code autocomplete works, \`tsc\` builds with no errors. You run \`node dist/index.js\` and it crashes with 'MODULE\_NOT\_FOUND' pointing to \`@app/utils\`. Inspecting the compiled JS, you see \`require\('@app/utils'\)\` preserved literally. You realize Node.js has no knowledge of TypeScript path mappings. Searching the error leads to \`tsconfig-paths\`. You install it, add \`-r tsconfig-paths/register\` to your start script, and the app boots. Later, you discover Node.js subpath imports \(the 'imports' field in package.json\) supported by TypeScript 4.7\+ via 'moduleResolution: NodeNext', which resolves this natively without external tools.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T03:51:44.760921+00:00— report_created — created