0

I've installed TypeScript using the command below.

npm install -g typescript

The editor mentioned that it was too old so I used this guide to get the newest like this.

npm install -g typescript@next

No error messages, all seems great. But I wanted to verify what version I've got so I used this answer and executed the following.

npm list typescript

It said empty and also gave me an error. Then I tried to show all packages like this.

npm list

No error but nothing's listed. In still says empty. I executed the commands from PowerShell and I was both in a root directory and then also in the project's directory.

What am I missing? Probably something very stupid and basic.

Community
  • 1
  • 1
  • Depends on the OS. I would suggest you start by `which npm` or `which node` –  Oct 11 '16 at 05:25
  • Check if you have other versions installed. Do you have a symbolic link that might be pointing to an older version? – Dandy Oct 11 '16 at 06:01
  • @Dandy I might have. How do I check it? I ran *npm install typescript@next* to get the latest version **but** I believe there was something about an outdated version in the IDE. Not sure at the moment and I'm kind of scared of this whole thing. Sorry... How do I check the symbolic links and older version, please? –  Oct 11 '16 at 06:16
  • 3
    In my recent experience with npm, I downloaded an older version that pointed to a `nodejs` folder and not a `node` folder or the other way round I can't remember. So I had to link it via a symbolic link in order to an issue I was having. This actually caused more problems then it solved. Did you do this? Either way, my suggestion would be purging/uninstalling npm if you're just starting out and following this to ensure you have the latest stable release of npm: https://docs.npmjs.com/getting-started/installing-node – Dandy Oct 11 '16 at 06:24
  • @CowAbunga If you want to install the latest version of the package you should use `@latest`, for example `npm i -g typescript@latest` – peteb Oct 11 '16 at 06:34
  • 1
    @Dandy The most surefire way I've found to install the latest version of NPM is by using **cURL**, `curl -L "https://npmjs.com/install.sh" | sudo sh`, if you're running on windows you'll need Cygwin or another shell like Git Bash, also on windows you can leave out the sudo – peteb Oct 11 '16 at 06:36
  • @peteb This is also a very good suggestion ^ – Dandy Oct 11 '16 at 06:36

2 Answers2

3

With NPM, whenever you want to determine if something is installed locally or globally you need to specify that, just like you do when you're installing a package. By default, if you don't specify the global flag -g then npm will look within the current working directory.

npm list -g typescript

peteb
  • 18,552
  • 9
  • 50
  • 62
  • Just tested again with *npm list -g typescript* but got the same result... What else can be wrong? –  Oct 11 '16 at 05:34
  • I just ran the above command after doing `npm i -g typescript` and it was listed, perhaps try adding a depth option of 0, `npm ls -g --depth=0`. I'm running on Windows 7. – peteb Oct 11 '16 at 05:42
  • What is the "i" doing there? –  Oct 11 '16 at 05:58
  • 1
    `npm i` is an alias for `npm install` – peteb Oct 11 '16 at 05:59
  • But doesn't it **install** the package (if it's not installed already) and **first then** it lists it? It's so confusing... –  Oct 11 '16 at 06:11
  • Even if the package has already been installed, it is installed. What I said in my previous comment was, I installed `typescript` globally using `npm i -g typescript`, then I listed all my globally installed packages using `npm ls -g` and typescript was listed as globally installed. Have you tried using CMD or Git Bash to interact with NPM instead of Powershell? – peteb Oct 11 '16 at 06:14
  • @I haven't got that far. Very noob. Most scared. So confused. :) I see what you've done now - thanks. I'll stick with depth at the moment (I've seen other suggestions on that too). Well, if it would be easy, it wouldn't be exciting, right? –  Oct 11 '16 at 06:19
0

I'm getting the following for a locally installed package in Tester01 directory.

PS C:\Users\_\GitHub\Tester01> npm list
C:\Users\_\GitHub\Tester01
└── typescript@2.0.3

PS C:\Users\_\GitHub\Tester01> npm list -g
C:\Users\_\AppData\Roaming\npm
└── typescript@2.1.0-dev.20161010

When I exit the directory where TypeScript is locally installed I get this.

PS C:\Users\_\GitHub\Tester01> cd..
PS C:\Users\_\GitHub> npm list
C:\Users\_\GitHub
└── (empty)

PS C:\Users\_\GitHub> npm list -g
C:\Users\_\AppData\Roaming\npm
└── typescript@2.1.0-dev.20161010

If you only want to list the package that interests you (can't see the sane reason for that so I might be misunderstanding the question but still...) this is the syntax.

PS C:\Users\_\GitHub\Tester01> npm list -g typescript@2.1.0-dev.20161010
C:\Users_\AppData\Roaming\npm
└── typescript@2.1.0-dev.20161010

However, I've seen this answer but on my system (Win 10) it seems not to work. I've updated NPM to the latest version too (ver 3.10.8) to make sure but still get the error. I guess if you want to list them, you might use one of the following (although I don't like the syntax getting lengthy and I'm not certain on the details of what those are doing on a fundamental level).

PS C:\Users\_\GitHub\Tester01> npm list typescript --depth=0
C:\Users_\GitHub\Tester01
└── typescript@2.0.3

PS C:\Users\_\GitHub\Tester01> npm list install typescript
C:\Users\_\GitHub\Tester01
└── typescript@2.0.3

Community
  • 1
  • 1
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
  • The latest version of NPM is v3.10.9 not v2.15.9, also the differences between v2 and v3 of NPM are quite dramatic. – peteb Oct 11 '16 at 06:15
  • @peteb Hehe, I got the latest version of **Node** and forgot to update NPM. My bad - it's 6 AM at my place. I should be sleeping, not horsing around on the internet... Thanks for the correction, mate. – Konrad Viltersten Oct 11 '16 at 06:26