ts-node Run Configuration error

I followed the setup guide here https://www.jetbrains.com/help/idea/running-and-debugging-typescript.html#ws_ts_run_debug_server_side but get this Error:

Error: Cannot find module 'ts-node/register'

My configuration looks like this:

I also tried to add tsconfig file to the Application parameters but no luck (--project tsconfig.json).

The script works fine if I run it from iTerm with the globally installed ts-node but not within IntelliJ.
I tried it with a local installation of ts-node and pointing to ./node_modules/ts-node/register but no luck either.

0
4 comments

To run with --require ts-node/register, you have to install ts-node locally in your project using npm i ts-node. You can't require global modules. Once you do this, the error should go away

0
Avatar
Permanently deleted user

It is installed locally in the project:

But still I get:

/usr/local/bin/node --require ts-node/register /path/to/script/script.ts
internal/modules/cjs/loader.js:796
throw err;
^

Error: Cannot find module 'ts-node/register'
0

strange. What is a result of running the same command (

/usr/local/bin/node --require ts-node/register /path/to/script/script.ts

) in the same directory in terminal?

Also, is the node_modules in the directory you're working in and not some child directory? This is pure node.js resolution here, not related to ts-node or the IDE...

0
Avatar
Permanently deleted user

I used the wrong Working directory. Had to go a level deeper and now everything works as expected.

Thx for your help.

2

Please sign in to leave a comment.