我想安装typescript,所以我使用了下面的命令:

npm install -g typescript 

和测试TSC——版本,但它只是显示' TSC命令未找到'。我尝试了stackoverflow, github和其他网站中建议的许多方法。但这并不奏效。我怎么知道typescript被安装和它在哪里。

我的操作系统是Unix, OS X El Capitan 10.11.6 节点版本为4.4.3, NPM的版本是3.10.5


当前回答

对于mac用户,你不需要重启你的笔记本电脑或执行任何其他命令

使用brew install typescript

其他回答

检查你的npm版本 如果没有正确安装,请先安装 执行NPM install typescript -g 现在TSC <file_name>.ts 它会创建一个相应的.js文件。如< file_name > . js 现在尝试node <file_name>.js

我在Ubuntu 19.10 LTS上遇到了同样的问题。

为了解决这个问题,我运行了以下命令:

$ sudo apt install node-typescript

在那之后,我能够使用tsc。

在Windows 10上,我通过添加%APPDATA%\npm到路径来解决这个问题

这个答案是特定于MAC上的iTermV2的

首先,我需要在NPM安装期间以sudo (admin)的身份安装 Sudo NPM install -g typescript NPM将库安装在/usr/local/ cellar /node/<您的最新版本>/lib/node_modules/typescript文件夹下,符号链接安装在/usr/local/ cellar /node/<您的最新版本>/bin/tsc

因此我去~/。zshrc (.bashrc,如果您使用bash),并添加/usr/local/ cellar /node/<您的最新版本>/bin到$PATH。

通过source ~/重新加载shell配置文件。zshrc(。Bashrc)

以上这些对我都没用。

我也试过这个,

yum install typescript 

能够千方百计地编译如下。不推荐,只是一个变通办法。

只要使用npm在本地安装,就像npm install typescript一样,并在node_module文件夹中验证,如果已经下载。然后跑,

./node_modules/typescript/bin/tsc  --help
./node_modules/typescript/bin/tsc  //this line actually runs and compile and generate the compiled file.