簡體   English   中英

為什么在安裝 npm i typescript 之后,`npx tsc --init` 使用舊版本(V1.5.3)但更新(V4.1.3)?

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

當在沒有安裝 typescript 的情況下使用 npx npx tsc --init時,NPM 似乎--init通過動作下載tsc ,並且確實使用了一些命令,但我沒有意識到它的全部(因為它沒有)舊版本的tsc 那很煩人,它應該使用最新的:)

要自己重現此問題,請確保您沒有全局安裝 typescript 並且不在 NPM 項目中(使用 package.json)。 然后輸入npx tsc --version :你會得到

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

顯然解決方法是先安裝npx ,然后沒有 npx 的意義,是嗎? 只有這樣我才能獲得最新版本:

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可能是因為它在搜索排名中下降了很多。

他的回答有更多細節和提示,使 npx 在不安裝npx的情況下仍然可以工作: npx npx -p typescript tsc (-p 表示“要安裝的包”。)


輸入問題后,似乎以前曾問過類似的問題。 但是這個問題與虛擬機無關(原始問題): “npx tsc --version”report different TypeScript version inside virtual machine

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM