'How to fix 'tsc: command not found'

I'm currently trying to install typescript on my machine for the first time. After installing node I run the following command:

sudo npm -g install typescript

This yields what appears to be a positive install message

/Users/mac/.npm-global/bin/tsc -> /Users/mac/.npm-global/lib/node_modules/typescript/bin/tsc /Users/mac/.npm-global/bin/tsserver -> /Users/mac/.npm-global/lib/node_modules/typescript/bin/tsserver + [email protected] updated 1 package in 0.924s

After this, I check to see if the install was successful but running tsc --version and receive the following error:

tsc: command not found

From another thread I have tried:

restarting the terminal restarting the machine reinstalling nodejs + then run sudo npm install typescript -g

I have also tried updating my bash profile with the following line:

export PATH="$PATH:"/Users/mac/.npm-global/lib/node_modules/typescript/bin/tsc"";

I am not confident typescript resides in the location I listed. Is there a way to confirm?

Any help would be greatly appreciated.



Solution 1:[1]

The following issue was fixed pretty easily. From your terminal open your bash profile:

open ~/.bash_profile

Edit your path to direct to the bin and not the executable (your path may vary see path after install):

/Users/mac/.npm-global/lib/node_modules/typescript/bin/

Save and close your file.

Reload your bash profile:

source ~/.bash_profile

Confirm all is working by checking the version:

tsc -v

Solution 2:[2]

(2020) This helped for me npx tsc app.ts

Solution 3:[3]

For those who are still trying and want a fresh answer, I will suggest do the following. If it still shows "tsc: command not found" in your terminal, do:

cd ~/.npm-global/lib/node_modules/typescript/bin

then do pwd to get the absolute path of the directory

once you pwd, copy what it shows and type this to your profile:

export PATH=$PATH:<your_pwd_directory_path_that_you_copied>

restart your terminal and rerun tsc -v or tsc --version and it should work out

Solution 4:[4]

May be this can help you

First type

npm bin -g

Add the execution result of the above command to your PATH.

export PATH=""

Hope this may help to solve your problem, And if not let me know.

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 enzo
Solution 2 Y g
Solution 3 Zeid Tisnes
Solution 4 exe