简体   繁体   中英

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). I can never seem to get TS compiling properly. The latest error I got on the VSCODE terminal (which is different to the set of errors I was getting on the console) was:

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:

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

the correct way is installing @types/node by npm command in VSCode terminal (MENU: View > Integrated Terminal):

npm install @types/node --save-dev

Before you install it, you'd better delete "@types" folder manually.

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