'tsc command not found' in compiling typescript

后端 未结 15 879
耶瑟儿~
耶瑟儿~ 2020-12-05 02:02

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

npm install -g typescript 

and test tsc --version, but it just

相关标签:
15条回答
  • 2020-12-05 02:05
    1. Check your npm version

    2. If it's not properly installed, then install it first

    3. run this command npm install typescript -g

    4. now tsc <file_name>.ts

    5. It'll create a corresponding .js file. eg <file_name>.js

    6. now try node <file_name>.js

    0 讨论(0)
  • 2020-12-05 02:05

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

    0 讨论(0)
  • 2020-12-05 02:06

    None of above answer solve my problem. The fact is that my project did not have type script installed. But locally I had run npm install -g typescript. So I did not notice that typescript node dependency was not in my package json.

    When I pushed it to server side, and run npm install, then npx tsc I get a tsc not found. In facts remote server did not have typescript installed. That was hidden because of my local global typescript install.

    0 讨论(0)
  • 2020-12-05 02:07

    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 :)

    0 讨论(0)
  • 2020-12-05 02:10

    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

    0 讨论(0)
  • 2020-12-05 02:10

    This answer is specific for iTermV2 on MAC

    1. First of all, I needed to instal as sudo (admin) 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)
    0 讨论(0)
提交回复
热议问题