【问题标题】:Cannot find namespace NodeJS找不到命名空间NodeJS
【发布时间】:2017-01-11 16:04:31
【问题描述】:

我正在使用 Ionic2 和 socket.io

当我执行ionic serve 时,我在终端中收到此错误:

TypeScript error: typings/globals/socket.io/index.d.ts(357,30): Error TS2503: Cannot find namespace 'NodeJS'.
TypeScript error: typings/globals/socket.io/index.d.ts(739,28): Error TS2503: Cannot find namespace 'NodeJS'.

节点版本为 4.2.6

我的 typings.json 看起来像这样:

{
  "dependencies": {},
  "devDependencies": {},
  "globalDependencies": {
    "es6-shim": "registry:dt/es6-shim#0.31.2+20160602141504",
    "socket.io": "registry:dt/socket.io#1.4.4+20160317120654",
    "socket.io-client": "registry:dt/socket.io-client#1.4.4+20160317120654"
  }
}

如果我打开 typings/globals/socket.io/index.d.ts(使用 sublimeText),我会看到:

你也可以看到 sublimeText 抱怨 NodeJS 命名空间。

【问题讨论】:

    标签: angular ionic-framework socket.io ionic2


    【解决方案1】:

    Node Typescript 项目也有类似的问题。原来我只是没有将 Node 设置为全局依赖项。

    typings install dt~node --global --save-dev
    

    快捷方式:

    typings i -GD dt~node
    

    【讨论】:

      【解决方案2】:

      你能提供你的typings.json吗?

      尝试更新到最新的提交7de6c3dd94feaeb21f20054b9f30d5dabc5efabd

      我也有同样的问题(使用不同的命名空间),更新修复它。

      https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/socket.io-client/socket.io-client.d.ts

      编辑: 试试:

      "socket.io": "github:DefinitelyTyped/DefinitelyTyped/socket.io/socket.io.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd",
      "socket.io-client": "github:DefinitelyTyped/DefinitelyTyped/socket.io-client/socket.io-client.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd"
      

      【讨论】:

      • 我尝试按照您的建议更新我的 typings.json 文件,但仍然无法正常工作。我已经编辑了问题,看看我上传的图片。
      猜你喜欢
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      • 2020-12-28
      • 2015-06-20
      • 2012-07-14
      • 2011-03-10
      • 2017-08-13
      相关资源
      最近更新 更多