简体   繁体   English

将Typescript与Node.js结合使用-找不到index.d.ts

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

A friend recommended that I swap over to Typescript from javascript, as a way to deal with the problems I was having implementing promises in loops and conditionals (TS has async/await functionality). 一位朋友建议我从javascript切换到Typescript,以解决我在循环和条件中实现promise时遇到的问题(TS具有异步/等待功能)。 I can never seem to get TS compiling properly. 我似乎永远无法正确编译TS。 The latest error I got on the VSCODE terminal (which is different to the set of errors I was getting on the console) was: 我在VSCODE终端上遇到的最新错误(与我在控制台上遇到的错误集不同)是:

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

So I created that directory structure and put index.d.ts in there and now I am getting these errors: 因此,我创建了该目录结构,并将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'.

it's not a correct way to solve your problem by doing: 这不是通过以下方法解决问题的正确方法:

created that directory structure and put index.d.ts in there 创建了该目录结构,并将index.d.ts放在其中

the correct way is installing @types/node by npm command in VSCode terminal (MENU: View > Integrated Terminal): 正确的方法是通过VSCode终端中的npm命令安装@types/node (菜单:视图>集成终端):

npm install @types/node --save-dev

Before you install it, you'd better delete "@types" folder manually. 在安装它之前,最好手动删除“ @types”文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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