【问题标题】:Using Typescript with Nodejs - Can't find index.d.ts将 Typescript 与 Nodejs 一起使用 - 找不到 index.d.ts
【发布时间】:2018-02-22 21:19:22
【问题描述】:

一位朋友建议我从 javascript 切换到 Typescript,以解决我在循环和条件中实现 Promise 时遇到的问题(TS 具有 async/await 功能)。我似乎永远无法正确编译 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'.

【问题讨论】:

  • 最新版本的Node有async/await。
  • ...是 6.x 吗?
  • nodejs.org 8.5 是最新版本。 Async/Await 到达版本 8。
  • 好的。我该如何更新到该版本?我是节点新手
  • 我喜欢n - 它使版本之间的切换变得容易:github.com/tj/n

标签: node.js typescript ecmascript-2017


【解决方案1】:

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

创建了那个目录结构并将 index.d.ts 放在那里

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

npm install @types/node --save-dev

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

【讨论】:

    猜你喜欢
    • 2012-12-14
    • 1970-01-01
    • 2020-06-30
    • 2020-11-26
    • 2016-11-10
    • 2021-04-09
    • 1970-01-01
    • 2017-10-13
    • 2017-02-19
    相关资源
    最近更新 更多