Home > Back-end >  Why does ts-node think it has a src directory, if when I look in node_modules there is none?
Why does ts-node think it has a src directory, if when I look in node_modules there is none?

Time:05-25

I am running my project using ts-node and I get the following error

TSError: ⨯ Unable to compile TypeScript:
spec/crons/dailyjob.spec.ts(51,9): error TS2589: Type instantiation is excessively deep and possibly infinite.

    at createTSError (C:\Users\joe\Documents\projects\client1\node_modules\ts-node\src\index.ts:820:12)
    at reportTSError (C:\Users\joe\Documents\projects\client2\node_modules\ts-node\src\index.ts:824:19)
....

I am curious what is going on, so I want to set a breakpoint at index.ts. But when I look in the ts-node directory, there no such src directory. It doesn't exist. Yet the script thinks it is running code from there.

Where is it?

ts-node directory

CodePudding user response:

You are running a distribution version of the ts-node module, not its development source code. The paths being logged are being mapped from the distribution files you're using to their original source paths which need not exist on your machine.

As you can see on this attached picture, the file node_modules/ts-node/dist/index.js.map tells you that the file index.js maps to ../src/index.ts before build, which is the path that gets logged to the end-user of the module.

index.js.map excerpt

These files are remapped because the stack traces of the module are meant to aid the developers of the module debug their builds, not the projects that use it.

  • Related