-1

I have TypeScript and ts-node installed globally and have the following files/directories -

+tsproject
    +src
        -main.ts
    -tsconfig.json

I can compile the main.ts file with tsc src/main.ts command or execute it directly with ts-node src/main.ts command. However, I'd like to use the commands tsc main.ts and ts-node main.ts instead, while setting some configuration for the path src so that the compiler knows where the main.ts file is located.

I have tried setting "rootDir": "src/" in the tsconfig.json file, but it didn't work - basically both commands complain about main.ts not being found.

My main purpose would be executing a specific file with ts-node. Any suggestions?

atiyar
  • 7,762
  • 6
  • 34
  • 75

1 Answers1

-1

If you have a tsconfig.json that specifies an include (such as ["src/**/*.ts"]), then you simply need to run tsc, not tsc main.ts in order to compile. Read more about tsconfig.json and its settings here. However, there's no easy way to get ts-node to change its root directory. Note that rootDir is not meant to be the source directory, so "rootDir": "src/" can break things or cause inconvenience.

Aplet123
  • 33,825
  • 1
  • 29
  • 55
  • My main purpose is executing a specific file with `ts-node`. I don't think `include` would help. – atiyar Nov 21 '20 at 14:20