您正在使用的 create-react-app
版本不支持 --template
選項。因此,--template typescript
沒有任何效果,您的項目中沒有生成 .tsx
文件。
至于為什么 npx create-react-app
不使用支持 --template
的版本,我懷疑您在本地全局安裝了舊版本的 create-react-app
。我懷疑這是因為:
npx
可以運行本地安裝的包(不僅限于遠(yuǎn)程包):
– npx
文檔
npx
會提示是否安裝遠(yuǎn)程包,但您的輸出沒有顯示此提示。提示如下所示:
Need to install the following packages: create-react-app@x.y.z Ok to proceed? (y)
您可以通過檢查全局安裝的包來驗證上述內(nèi)容:
npm list -g
yarn global list
在驗證了您是否全局安裝了 create-react-app
之后,您可以卸載它:
npm uninstall -g create-react-app
yarn global remove create-react-app
create-react-app
還建議您不要全局安裝版本: