如何修复“ TSC:找不到命令” [英] 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
+ typescript@3.4.4更新了0.924s中的1个程序包
/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
此后,我检查安装是否成功,但运行 tsc --version
并收到以下错误:
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:
重启终端
重启机器
重新安装nodejs +然后运行 sudo npm install typescript -g
我也尝试过更新bash pro带有以下行的文件:
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?
任何帮助将不胜感激。
推荐答案
以下问题很容易修复。在终端上打开bash个人资料:
The following issue was fixed pretty easily. From your terminal open your bash profile:
打开〜/ .bash_profile
open ~/.bash_profile
编辑路径以定向到bin而不是可执行文件(您的路径可能会有所不同,请参阅安装后的路径):
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/
/Users/mac/.npm-global/lib/node_modules/typescript/bin/
保存并关闭文件。
重新加载您的bash个人资料:
Reload your bash profile:
源〜/ .bash_profile
source ~/.bash_profile
通过检查版本确认所有工作正常:
Confirm all is working by checking the version:
tsc -v
这篇关于如何修复“ TSC:找不到命令”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!