找不到名称空间NodeJS

时间:2016-09-03 20:24:46

标签: angular ionic-framework socket.io ionic2

我正在使用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),我会看到: enter image description here

正如您所看到的,sublimeText也抱怨NodeJS名称空间。

2 个答案:

答案 0 :(得分:1)

与Node Typescript项目有类似的问题。结果我没有将Node设置为全局依赖。

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

快捷键:

typings i -GD dt~node

答案 1 :(得分:0)

您能否提供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"