typescriptnpmvisual-studio-codeinstallation

TypeScript installed, but not being recognized by VS Code or Windows


I've recently been working on a small project in VS Code that is primarily typescript.

I committed it to a GitHub repository and downloaded it onto a machine that I regularly use for TypeScript development. However, when I try to build my VS Code project, I get the error:

tsc : The term 'tsc' is not recognized as the name of a cmdlet, function, 
script file, or operable program. Check the spelling of the name, or if a 
path was included, verify
that the path is correct and try again.
At line:1 char:1
+ tsc
+ ~~~
+ CategoryInfo          : ObjectNotFound: (tsc:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

After reading other StackOverflow questions on the subject, I tried a few things:

  1. Installed typescript using npm, with the command npm install -g typescript - I received no error messages, so it seems the install was successful (confirmed in Step 3).
  2. Checked my envrionmental variables to ensure I wasn't pointing to any unusual locations for the tsc compiler. I found none.
  3. Ran the command npm list -g to ensure that TypeScript installed (it did.)
  4. As a sanity check, ran the command from the path found in Step 3, resembling C:\Users\MyUserName\AppData\Roaming\npm\tsc - the path ran
  5. With the sanity check's results in mind, opened a clean command prompt, and tried running tsc -v - command was not recognized by the OS.
  6. Ran the command setx path "%paths%:C:\MyUserName\AppData\Roaming\npm" to try to add the npm global directory to the system environment paths variable. Upon running the command, closed the command line, opened a new one, and tried an unqualified tsc command. No luck.

It's almost as if the npm install -g typescript command isn't enough to actually install TypeScript such that the system recognizes it on a global basis (despite using the -g/"global" flag). Clearly I'm missing something. What is it that I'm missing?


Solution

  • After updating node.js to 10.13.0 LTS, after closing and re-opening both my command prompt and VS Code, tsc runs.

    So, be sure you update node if you start getting funny feedback from tsc!