Recently, I've been immersed in a VS Code project that predominantly uses TypeScript.
After committing the project to GitHub and downloading it onto my usual machine for TypeScript development, I encountered an issue when trying to build the project in VS Code:
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
Upon researching similar issues on StackOverflow, I attempted several solutions:
- Installed TypeScript using npm with the command
npm install -g typescript
. The installation showed no errors, indicating that it was successful (confirmed later in Step 3). - Checked my environmental variables to ensure there were no unusual paths pointing to the
tsc
compiler. None were found. - Ran the command
npm list -g
to confirm that TypeScript was indeed installed globally (which it was). - As a precautionary measure, ran the command from the path identified in Step 3, resembling
, and it executed successfully.C:\Users\MyUserName\AppData\Roaming\npm\tsc
- Considering the results of the previous check, I opened a fresh command prompt and attempted running
tsc -v
, but the OS did not recognize the command. - Executed the command
to add the npm global directory to the system environmentsetx path "%paths%:C:\MyUserName\AppData\Roaming\npm"
paths
variable. Despite this modification, restarting the command line and attempting an unqualifiedtsc
command yielded no results.
It seems that simply running npm install -g typescript
does not effectively install TypeScript in a manner that the system acknowledges on a global scale, despite using the -g/"global" flag. Clearly, something crucial eludes me. Can anyone pinpoint what exactly I'm missing?