问题
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 + typescript@3.4.4 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.
回答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
来源:https://stackoverflow.com/questions/55767486/how-to-fix-tsc-command-not-found