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

标签 node.js typescript ecmascript-2017

一位 friend 建议我从 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'.

最佳答案

这不是解决问题的正确方法:

created that directory structure and put index.d.ts in there

正确的方法是在 VSCode 终端中通过 npm 命令安装 @types/node(菜单: View > 集成终端):

npm install @types/node --save-dev

安装之前,最好手动删除“@types”文件夹。

关于node.js - 将 Typescript 与 Nodejs 结合使用 - 找不到 index.d.ts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46209795/

相关文章:

javascript - node.js ffi 导入常量

node.js - 无法从Docker容器(node.js客户端)连接到Elasticsearch

javascript - setInterval 没有被清除,函数一直在执行

javascript - 按字符串对对象数组进行排序与​​行为不同的数值

javascript - 为什么 await 之后的代码没有立即运行?它不应该是非阻塞的吗?

javascript - 类型 'entries' 上不存在属性 'ObjectConstructor'

javascript - Angular, sails 路由问题

TypeScript 属性装饰器 : access to other properties

typescript - 为类的方法声明一个附加成员

javascript - 异步等待中的 try catch 问题