The difference between "npm run tsc" vs spawn('tsc')

Viewed 432

I want to have a script, which will compile .ts files in my multiple repos. I try to run compilation via spawnSync('tsc file.ts') but I end up with tsc is not recognized as internal/external command. Compiling the same file with npm run tsc file.ts works fine. What am I missing here?

1 Answers

So while running npm run tsc file.ts additional binary is added and local typescript is used to execute the command. When running `spawn('tsc file.ts') a global installed typescript is needed, and when not found, throws eerror.

Related