簡體   English   中英

將Typescript與Node.js結合使用-找不到index.d.ts

[英]Using Typescript with Nodejs - Can't find index.d.ts

一位朋友建議我從javascript切換到Typescript,以解決我在循環和條件中實現promise時遇到的問題(TS具有異步/等待功能)。 我似乎永遠無法正確編譯TS。 我在VSCODE終端上遇到的最新錯誤(與我在控制台上遇到的錯誤集不同)是:

error TS6053: File 'c:/stuff/node_modules/@types/node/index.d.ts' not found.

因此,我創建了該目錄結構,並將index.d.ts放在其中,現在出現以下錯誤:

node_modules/@types/node/index.d.ts(6,25): error TS2307: Cannot find module 'stream'.
node_modules/@types/node/index.d.ts(14,32): error TS2304: Cannot find name 'Buffer'.
node_modules/@types/node/index.d.ts(15,78): error TS2304: Cannot find name 'Buffer'.
node_modules/@types/node/index.d.ts(23,39): error TS2304: Cannot find name 'Buffer'.

這不是通過以下方法解決問題的正確方法:

創建了該目錄結構,並將index.d.ts放在其中

正確的方法是通過VSCode終端中的npm命令安裝@types/node (菜單:視圖>集成終端):

npm install @types/node --save-dev

在安裝它之前,最好手動刪除“ @types”文件夾。

暫無
暫無

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

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