Cesco
Cesco

Reputation: 3870

How to upgrade Typescript to the latest version?

I have a MacBook Pro with OS X 10.8.2 Some time ago I installed Typescript and today I'd like to upgrade that installation to the latest version available (so far, v0.8.3). I wrote this command from the terminal:

sudo npm install -g typescript

But this is what I got on the display:

npm http GET https://registry.npmjs.org/typescript
npm http 304 https://registry.npmjs.org/typescript
/usr/local/bin/tsc -> /usr/local/lib/node_modules/typescript/bin/tsc
[email protected] /usr/local/lib/node_modules/typescript

Does this means that I still have version 0.8.0 installed on my computer? I tried to see if the tsc command has a -v or a -version parameter but I haven't found it, so I still uncertain if I have upgraded Typescript to the latest release or if I'm still stuck with an older version.

Upvotes: 58

Views: 118610

Answers (12)

Heleno Salgado
Heleno Salgado

Reputation: 1

Instead of npm, I used npx and it worked.

Upvotes: 0

Chris22
Chris22

Reputation: 2043

UPDATE 9/26/2022

After running npm install typescript@latest -g I got the errors:

npm ERR! code EEXIST
npm ERR! path C:\Users\chrisds\AppData\Roaming\npm\tsc
npm ERR! EEXIST: file already exists
npm ERR! File exists: C:\Users\chrisds\AppData\Roaming\npm\tsc
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\chrisds\AppData\Local\npm-cache\_logs\2022-09-26T20_55_57_959Z-debug-0.log

So I found the path and deleted all instances of tsc i.e.: tsc, tsc.cmd, tsc.psl, tsserver, tsserver.cmd, tsserver.psl

And then ran npm install typescript@latest -g again and it worked.

C:\Users\chrisds\Documents\typescript-angular>tsc -v

Version 4.8.3

Upvotes: 1

Sunny
Sunny

Reputation: 119

  1. I had Visual Studio installed on my Windows OS computer, which added its own version of TypeScript installation into the System Path
  2. Uninstalled 'TypeScript for Visual Studio' from Programs and Features(or 'Add or remove programs')
  3. Installed latest typescript. From command prompt 'npm install -g typescript@latest'
  4. Issue solved!

I know this is an old Question, but I faced a similar issue and none of the answers here solved it, posting my answer for anyone else in the same boat.

Upvotes: 2

Legends
Legends

Reputation: 22672

Open a command line tool cmd.exe/Git Bash and execute:

 npm install -g typescript@latest

The command will do the following:

Check if Typescript is installed and ..

  1. if installed already, update it to the latest version
  2. if not installed, install the latest version

It has been reported that the following command will not work reliably when you already have typescript installed:

npm update -g typescript@latest

Test the version using

tsc -v  // prints out the locally installed typescript version

enter image description here

Furthermore you can check, which is the latest available version for typescript in the npm registry:

npm view typescript version  // prints the latest available version in the npm registry

Upvotes: 14

Adam Weber
Adam Weber

Reputation: 2395

I encountered the same issue and none of the popular answers resolved the problem for me. I'm on Windows 10 with Visual Studio 2017.

I tried using where tsc from the console to determine where the path to tsc was resolving. The first entry was similar to: C:\Program Files (x86)\Microsoft SDKs\TypeScript\x.xx. So I checked the PATH variable (both System and User) and that path was nowhere to be found.

I finally stumbled across this comment on GitHub: https://github.com/Microsoft/TypeScript/issues/4971#issuecomment-144184935

Which pointed me in the right direction. I use Console2 and my default console tab spawns a Visual Studio-enhanced console via this .bat file: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat

That .bat file doesn't contain anything TypeScript-specific, but it does run all the .bat files found in C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\vsdevcmd\ext. And one of those files is conspicuously named typescript.bat. I simply renamed that filed to some other extension, then re-opened a console and now everything is great.

Not sure if this will bork up anything in Visual Studio, but I don't use it for TypeScript. And I suspect a future Visual Studio update may put that file back in place. But it works for now.

Upvotes: 0

godblessstrawberry
godblessstrawberry

Reputation: 5058

I just faced this issue on the windows 8 machine with blocked admin access where I was unable to uninstall global typescript, modify PATH etc.

Here's how to launch typescript projects in this case:

  1. install local typescript version for project npm install typescript@latest ( avoid -g param)
  2. add build scripts to package.json e.g.

    scripts: { "clean": "rimraf coverage build tmp", "build": "tsc -p tsconfig.release.json", "build:watch": "tsc -w -p tsconfig.release.json", "lint": "tslint -t stylish --project \"tsconfig.json\"", "test": "jest --coverage", "test:watch": "jest --watch" }

  3. run typescript compiler with the local version of typescript via npm run build:watch which will launch tsc -w -p tsconfig.release.json using project's local tsc from node_modules

Upvotes: 2

Heather Roberts
Heather Roberts

Reputation: 2148

I had the same problem on Linux, possibly related to using node version manager.

I fixed it by finding where tsc was and then manually going in and deleting those folders

$ which tsc
/home/vagrant/.nvm/versions/node/v6.9.5/bin/tsc

$ cd /home/vagrant/.nvm/versions/node/v6.9.5/bin/
$ ll
...
lrwxrwxrwx 1 vagrant vagrant       38 Nov 30 10:32 tsc -> ../lib/node_modules/typescript/bin/tsc*
lrwxrwxrwx 1 vagrant vagrant       43 Nov 30 10:32 tsserver -> ../lib/node_modules/typescript/bin/tsserver*
...

$ rm -rf ../lib/node_modules/typescript/ tsc tsserver

Upvotes: 3

Cesco
Cesco

Reputation: 3870

I just realised that I was using an old version of npm. I have upgraded npm to the latest version, then re-installed typescript and now I have the latest version of typescript installed on my computer.

Upvotes: 9

WonderHeart
WonderHeart

Reputation: 688

Even when i installed latest typescript, still i was getting version as 1.0.3 when doing tsc -v

The corrected answer didn't help me , but followed @BenR approach, removed this PATH C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\ from System Variables

enter image description here

and then opened new windows command prompt and then typed

tsc -v
Version 2.3.3

So now i was able to compile the typescript files using tsc file.ts

Hope this helps someone.

Upvotes: 14

Puneeth Rai
Puneeth Rai

Reputation: 1193

I had the same problem below procedure worked for me

Update NPM

npm install npm@latest -g

Update typescript

npm -g upgrade typescript

or

npm install typescript@latest -g

now you should see

tsc --version

Version 2.1.5

Upvotes: 81

vezenkov
vezenkov

Reputation: 4145

For those still struggling with that - try running WHERE tsc in Command Prompt or Node.js Command Prompt and you'll get all the locations it is installed. Remove the excessive location from PATH env var.

Upvotes: 17

BenR
BenR

Reputation: 2936

Since selected correct answer didn't help me I figured I'd share how I resolved the issue.

I had to remove C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\ from my PATH.

After that I could run this command and see the version I was expecting:

C:\>tsc --version
message TS6029: Version 1.5.3

Upvotes: 78

Related Questions