Report #61583
[bug\_fix] TypeScript path mapping not resolved at runtime \(Cannot find module '@myapp/shared'\)
Use tsconfig-paths/register with ts-node \(node -r tsconfig-paths/register\), or use tsc-alias after tsc to rewrite paths, or use Node.js native subpath imports \(imports field in package.json\) instead of TypeScript paths.
Journey Context:
Developer sets up a TypeScript monorepo with tsconfig.json paths mapping \(e.g., "@myapp/shared": \["packages/shared/src"\]\) to avoid relative imports like ../../../shared. TypeScript compilation \(tsc\) succeeds, but when they run node dist/apps/main/index.js, Node crashes with "Error: Cannot find module '@myapp/shared'". They check the compiled JS and see the import statement still says require\('@myapp/shared'\) - TypeScript paths are compile-time only and don't rewrite the emitted JS. They consider using module-alias but find it hacky. The solutions are: 1\) Use tsconfig-paths/register when running via ts-node \(node -r tsconfig-paths/register dist/main.js\) which patches Node's module resolution at runtime to respect tsconfig paths. 2\) Use tsc-alias \(a post-processor\) after tsc to rewrite the import paths in the dist folder to relative paths. 3\) Refactor to use Node.js native subpath imports by adding "imports": \{"\#shared": "./packages/shared/src/index.js"\} to package.json, which Node resolves at runtime without TypeScript-specific tooling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T09:51:20.170560+00:00— report_created — created