'tsc command not found' in compiling typescript

非 Y 不嫁゛ 提交于 2019-12-18 13:50:46

问题


I want to install typescript, so I used the following command:

npm install -g typescript 

and test tsc --version, but it just show 'tsc command not found'. I have tried many ways as suggested in stackoverflow, github and other sites. but it doesn't work. How could I know typescript is installed and where it is.

my OS is Unix, OS X El Capitan 10.11.6, node version is 4.4.3, npm version is 3.10.5


回答1:


A few tips in order

  • restart the terminal
  • restart the machine
  • reinstall nodejs + then run npm install typescript -g

If it still doesn't work run npm config get prefix to see where npm install -g is putting files (append bin to the output) and make sure that they are in the path (the node js setup does this. Maybe you forgot to tick that option).




回答2:


Easy fix for Mac I found. Just run these commands:

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

Nothing worked except this for me.




回答3:


I had to do this:

npx tsc app.ts



回答4:


If your TSC command is not found in MacOS after proper installation of TypeScript (using the following command: $ sudo npm install -g typescript, then ensure Node /bin path is added to the PATH variable in .bash_profile.

Open .bash_profile using terminal: $ open ~/.bash_profile;

Edit/Verify bash profile to include the following line (using your favorite text editor):

export PATH="$PATH:"/usr/local/lib/node_modules/node/bin"";

Load the latest bash profile using terminal: source ~/.bash_profile;

Lastly, try the command: $ tsc --version.




回答5:


I know this is an old question, but I had this same problem on Ubuntu 19.10 LTS.

To solve this I ran the following command:

$ sudo apt install node-typescript

After that, I was able to use tsc.

I hope it helps :)




回答6:


For windows:

Add the path by using command as below in command prompt:
path=%path%;C:\Users\\npm

As in my case, the above path was not registered for command.

%userprofile% in run windows, will give you path to C:\users\




回答7:


This works perfectly on Mac. Tested on macOS High Sierra

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

This generates the tsconfig.json file.




回答8:


you are all messing with the global installations and -path files. Just a little error might damage every project you have ever written, and you will spend the rest of the nite trying to get a console.log('hi') to work again:-=.

If you have run npm i typescript --save-dev in your project - just try to run:

npx tsc

and see if it works before messing with global stuff (unless ofc you really know what you are doing)

cheers




回答9:


This answer is specific for iTermV2 on MAC

  1. First of all, I needed to instal sudo during NPM install

    sudo npm install -g typescript

  2. NPM installs the libraries under /usr/local/Cellar/node/<your latest version>/lib/node_modules/typescript folder and symlinks at /usr/local/Cellar/node/<your latest version>/bin/tsc

hence I went ~/.zshrc ( .bashrc, if you use bash)and added /usr/local/Cellar/node/<your latest version>/bin to the $PATH.

  1. reload the shell profile via source ~/.zshrc (.bashrc in your case)



回答10:


I solved this on my machine by just running sudo npm install in the directory that I was getting the error.



来源:https://stackoverflow.com/questions/39404922/tsc-command-not-found-in-compiling-typescript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!