Report #68755
[bug\_fix] Error: Cannot find module '@app/shared' at runtime when using ts-node
Install 'tsconfig-paths' and preload it with ts-node using 'node -r tsconfig-paths/register -r ts-node/register src/index.ts' or set 'TS\_NODE\_TRANSPILE\_ONLY=true'.
Journey Context:
You have 'paths' configured in tsconfig.json and 'tsc' compiles successfully. However, when running 'ts-node src/index.ts', Node.js crashes with 'Cannot find module @app/shared'. You verify that the compiled JavaScript would work if you ran it \(because the paths are resolved at compile time, but ts-node executes TS directly\). You realize that ts-node compiles TypeScript to JavaScript using the compiler, but then uses Node.js's native 'require' to load the compiled modules. Node.js's module resolution knows nothing about TypeScript's 'paths' configuration. The fix is to use the 'tsconfig-paths' package, which registers a hook with Node.js's module system to intercept require calls and resolve them according to the paths in your tsconfig.json. You install it and preload the register module, and ts-node now resolves the paths correctly at runtime.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:53:20.328182+00:00— report_created — created