I want to install typescript, so I used the following command:
npm install -g typescript
and test tsc --version
, but it just
Check your npm
version
If it's not properly installed, then install it first
run this command npm install typescript -g
now tsc <file_name>.ts
It'll create a corresponding .js
file. eg <file_name>.js
now try node <file_name>.js
I solved this on my machine by just running sudo npm install
in the directory that I was getting the error.
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.
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 :)
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
This answer is specific for iTermV2 on MAC
First of all, I needed to instal as sudo
(admin) during NPM install
sudo npm install -g typescript
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.
source ~/.zshrc
(.bashrc in your case)