0

I was following a tutorial on typescript today and they were running tsc commands in the builtin terminal of VScode. I tried following along but I would get that the cmdlet 'tsc' is not recognized. I was never able to run any commands on the VScode builtin terminal, but I never bothered to setup. I decided to finally go about it and came across this post

Setting up code to be found in Path

prior to this I was able to run the line tsc sandbox.ts in a folder containing sandbox.ts to convert to sandbox.js so the command tsc was working fine. After following the post and running the command:

setx path "C:\Users{username}\AppData\Local\Programs\Microsoft VS Code\bin"

nothing really happened and I still wasnt abe to run any commands through the VScode terminal. However at this point tsc commands also didn't work inside of the Windows command prompt anymore. I reran the npm install and it was not recognizing the tsc command. I am still very new to environment variables and such so I do not know what happened. Does anyone have a solution?

Typescript installation

The OS that I am using is Windows 10.

SK99
  • 51
  • 5
  • 1. reset the terminal, 2. if that doesn't work run `npx tsc -v` – Samathingamajig Apr 22 '23 at 23:05
  • ok the npx tsc -v works, and all the tsc commands work as long as I have npx before it. Is there a way to configure my terminal to make it such that I can run tsc commands without typing npx? – SK99 Apr 23 '23 at 01:18

1 Answers1

1

It seems that you have your path a little bit messed up.

If you can run commands like node an npm but not things that you have installed using npm install -g then those things may be installed installed in the wrong place, or maybe you are using aaa different npm version (in a different location) than you think.

Everything you install with npm install -g is installed in the same plase as the node binary and the npm executaable.

Example of how it should work like:

  • which npm - prints /Users/rsp/opt/node/bin/npm npm is installed here)
  • which rimraf returns empty output and an error
  • rimraf - prints -bash: rimraf: command not found so no rimraf command in the path
  • npm install -g rimraf - [...] added 28 packages in 2s [...]
  • which rimraf - now it prints /Users/rsp/opt/node/bin/rimraf (note the same place as npm)

In your case to diagnose the problem, run the which command if it is available (or one of its alternatives for Windows) using commands like:

  • which node
  • which npm (write down the directory where it is, e.g. /a/b/c if which returned /a/b/c/npm)
  • which tsc
  • npm install -g rimraf (or any other module that installs executables)
  • which rimraf (should display the same directory aas for node and npm)
  • rimraf --help
  • ls /a/b/c (directory returned by which npm) note: use dir if ls doesn't work
  • see what is installed in this directory (there should be npm, node, rimraf)
  • npm remove -g rimraf

If there is something strange, like rimraf in a different directory than npm, etc. then I would suggest a afresh node installation and trying everything again (including installing typescript package to get the tsc command).

rsp
  • 107,747
  • 29
  • 201
  • 177