简体   繁体   中英

Why does `npx tsc --init` use an old version (V1.5.3) but newer (V4.1.3) after npm i typescript is installed?

When using npx tsc --init without typescript installed, NPM seems to go through the motions to download tsc , and has some commands, but not all (it doesn't have --init ), and I realize its because its using a really old version of tsc . Thats annoying, it should use the latest one:)

To reproduce this yourself, make sure you don't have typescript installed globally and also are not in a NPM project (with package.json). Then type npx tsc --version : you will get

npx: installed 1 in 0.868s
message TS6029: Version 1.5.3

Obviously the workaround is to install typescript first, but then there is no point of npx , is there? Only then do I get the latest version:

Version 4.1.3

As Estus Flask said in his answer here , when you use tsc without typescript installed, you are using the deprecated tsc package , which I personally wasn't able to find using https://www.npmjs.com/search?q=tsc probably because it has fallen way down in the search ranking.

His answer has more detail and tips to make npx still work without installing typescript: npx -p typescript tsc (-p means "Package to be installed.")


After typing the question, it looks like a similar question has been asked before. But this question has got nothing to do with virtual machines (the original question): "npx tsc --version" reports different TypeScript version inside virtual machine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM