Category: Next.js, React and TypeScript

TypeScript: alias paths works in the editor, but Node does not find the module

Read this guide in Polish

TS and IDE solve @/lib/config, but the running Node script reports MODULE NOT FOUND. paths in tsconfig are used to solve types and do not guarantee conversion of imports in the generated Node code.

How to determine the source of the error

Check the discrepancy between ts-node, Bundler, tsc and node by running the production command exactly.

Look at the generated JS files to see if the alias remained in the import specification.

What to do step by step

1. Configure compatible aliases in runtime/bundler or use direct relative import.

2 . For ESM code, consider the correct package imports and a coherent package export configuration.

How to check the score

The script after the construction starts without additional hacks, and the module is solved the same on CI and locally.

What to do

Do not assume that the basisUrl/paths itself in tsconfig changes the operation of imports in clean Node.js.