我想安装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上工作得很好。在macOS High Sierra上测试过

sudo npm install -g concurrently
sudo npm install -g lite-server
sudo npm install -g typescript
tsc --init

这将生成tsconfig。json文件。

其他回答

对于windows和yarn用户,请尝试yarn tsc——init

以上这些对我都没用。

我也试过这个,

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. 

在package.json

  "scripts": {
    "tsc": "./node_modules/typescript/bin/tsc",
    "postinstall": "npm run tsc"
  },

赫鲁库的部署对我很有用。 安装npm install -D typescript并在构建脚本“build”:“tsc”中写入tsc,不适合我。

这个答案是特定于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)

这在Mac上工作得很好。在macOS High Sierra上测试过

sudo npm install -g concurrently
sudo npm install -g lite-server
sudo npm install -g typescript
tsc --init

这将生成tsconfig。json文件。