'typescript: tsc is not recognized as an internal or external command, operable program or batch file

I am a beginner with type script. I am unable to compile the type script file.

As I hit Ctrl+Shift+B in the VS Code, i get the error "tsc is not recognised"

I used npm while downloading transcript.

C:\Users\sramesh>npm install -g typescript
C:\Users\sramesh\AppData\Roaming\npm\tsserver -> C:\Users\sramesh\AppData\Roaming\npm\node_modules\typescript\bin\tsserver
C:\Users\sramesh\AppData\Roaming\npm\tsc -> C:\Users\sramesh\AppData\Roaming\npm\node_modules\typescript\bin\tsc
C:\Users\sramesh\AppData\Roaming\npm
`-- [email protected]

Here is my tasks.json file

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "C:\\Users\\sramesh\\AppData\\Roaming\\npm\\node_modules\\typescript\\bin\\tsc",
    "isShellCommand": true,
    "args": [],
    "showOutput": "silent",
    "problemMatcher": "$tsc"
}

Can anyone help?



Solution 1:[1]

I'm using Windows OS and For some reason the marked answer didn't work for me.I tried tsc--init and i was returned the same error.I updated the path variable to C:\Users\"UserName"\AppData\Roaming\npm and this worked..

Note:replace Username with your own Username

Solution 2:[2]

I had a similar issue and didn't even showed the version of Typescript after typing tsc -v. Even i had to scratch my head for few days and couldn't solve it.

At last i did 4 things.

  1. installed latest version of nodejs which is i.e. 8.1.3
  2. installed npm which is 5.1.0 ( npm install npm@latest -g)
  3. installed typescript 2.4.1 ( npm install -g typescript)
  4. as suggested by @Uzair Sajid above. (tsc --init)

Now, I can see the TS version, and also compile the TS code.

Solution 3:[3]

After installation, simple solution I tried is just set the path variable in environment variables till folder where npm is installed.

C:\Users\"Username"\AppData\Roaming\npm

where Username will be your own username.

Then, open cmd, go to npm folder using cd AppData/Roaming/npm and type tsc , it will run. Now just close the cmd and open it again, and type tsc --version OR tsc, it will run successfully.

Solution 4:[4]

I tried using the command line to set the target.

tsc first.ts --target ES5

This created the first.js( compiled type script in javascript format).I manually moved this file to scripts folder.

Now when i ran the server using lite-server command. The browser could find the first.js file and ran the typescript code.

Solution 5:[5]

I had the same issue with typescript, 'tsc' not recognized in terminal.

Before I installed typescript with yarn like 'yarn global add typescript', And then I installed typescript with npm like 'npm install -g typescript' and the issue solved, Terminal knowing typescript commands and itself.

Maybe this answer would be helpful

Solution 6:[6]

I was able to solve this issue on my Windows 10 21H1 desktop by:

  1. Install the typescript package globally ? npm install -g typescript

  2. Updating the Path environment variable:

    • Search Environment Variables in the start menu
    • Select Edit the system environment variables
    • Select the Environment Variables... button in the Advanced section
    • Look in the System Variables section for the Path variable
    • Double click that variable
    • Select New...
    • Enter the location your npm config downloads global packages at. You can find out where by using the npm list -g command. For me, it was at C:\Users\MyUsername\AppData\Roaming\npm — be sure to replace MyUsername with your username
  3. Re/open an active terminal

  4. Use the tsc -v command to observe the result

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shardul Birje
Solution 2 Pramod Kumar Sharma
Solution 3
Solution 4 codingyo
Solution 5 Temurbek Ro'ziyev
Solution 6 BITWISE