TypeError:无法读取tsc.js中未定义的属性“length”

时间:2017-09-07 11:27:29

标签: node.js typescript

我使用typescript创建了一个nodejs api项目。但我无法启动它。这是我正在运行的命令

npm start

这是此命令的输出

> project1@1.0.0 prestart D:\Workspace
> tsc

D:\Workspace\node_modules\typescript\lib\tsc.js:9921
                for (var _i = 0, _a = node.jsDocPropertyTags; _i < _a.length; _i++) {
                                                                     ^

TypeError: Cannot read property 'length' of undefined
    at Object.forEachChild (D:\Workspace\node_modules\typescript\lib\tsc.js:9921:70)
    at setParentPointers (D:\Workspace\node_modules\typescript\lib\tsc.js:17392:12)
    at D:\Workspace\node_modules\typescript\lib\tsc.js:17392:64
    at visitNode (D:\Workspace\node_modules\typescript\lib\tsc.js:9533:24)
    at Object.forEachChild (D:\Workspace\node_modules\typescript\lib\tsc.js:9918:25)
    at setParentPointers (D:\Workspace\node_modules\typescript\lib\tsc.js:17392:12)
    at D:\Workspace\node_modules\typescript\lib\tsc.js:17392:64
    at visitNodes (D:\Workspace\node_modules\typescript\lib\tsc.js:9542:30)
    at Object.forEachChild (D:\Workspace\node_modules\typescript\lib\tsc.js:9891:24)
    at setParentPointers (D:\Workspace\node_modules\typescript\lib\tsc.js:17392:12)
    at bindChildrenWorker (D:\Workspace\node_modules\typescript\lib\tsc.js:15178:25)
    at bindChildren (D:\Workspace\node_modules\typescript\lib\tsc.js:15129:17)
    at bindContainer (D:\Workspace\node_modules\typescript\lib\tsc.js:15122:17)
    at bind (D:\Workspace\node_modules\typescript\lib\tsc.js:16214:21)
    at Object.forEach (D:\Workspace\node_modules\typescript\lib\tsc.js:275:30)
    at bindEach (D:\Workspace\node_modules\typescript\lib\tsc.js:15149:20)
    at visitNodes (D:\Workspace\node_modules\typescript\lib\tsc.js:9538:24)
    at Object.forEachChild (D:\Workspace\node_modules\typescript\lib\tsc.js:9707:24)
    at bindEachChild (D:\Workspace\node_modules\typescript\lib\tsc.js:15165:16)
    at bindChildrenWorker (D:\Workspace\node_modules\typescript\lib\tsc.js:15254:21)
    at bindChildren (D:\Workspace\node_modules\typescript\lib\tsc.js:15129:17)
    at bindContainer (D:\Workspace\node_modules\typescript\lib\tsc.js:15093:17)
    at bind (D:\Workspace\node_modules\typescript\lib\tsc.js:16214:21)
    at bindSourceFile (D:\Workspace\node_modules\typescript\lib\tsc.js:14851:17)
    at Object.bindSourceFile (D:\Workspace\node_modules\typescript\lib\tsc.js:14809:9)
    at initializeTypeChecker (D:\Workspace\node_modules\typescript\lib\tsc.js:36496:20)
    at Object.createTypeChecker (D:\Workspace\node_modules\typescript\lib\tsc.js:18543:9)
    at getDiagnosticsProducingTypeChecker (D:\Workspace\node_modules\typescript\lib\tsc.js:56042:93)
    at Object.getGlobalDiagnostics (D:\Workspace\node_modules\typescript\lib\tsc.js:56370:53)
    at compileProgram (D:\Workspace\node_modules\typescript\lib\tsc.js:59092:78)
    at compile (D:\Workspace\node_modules\typescript\lib\tsc.js:59051:26)
    at performCompilation (D:\Workspace\node_modules\typescript\lib\tsc.js:58940:33)
    at Object.executeCommandLine (D:\Workspace\node_modules\typescript\lib\tsc.js:58883:9)
    at Object.<anonymous> (D:\Workspace\node_modules\typescript\lib\tsc.js:59241:4)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (D:\Workspace\node_modules\typescript\bin\tsc:2:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.9.5
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! project1@1.0.0 prestart: `tsc`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project1@1.0.0 prestart script 'tsc'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the project1 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     tsc
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs project1
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls project1
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     D:\Workspace\npm-debug.log

和我的 package.json

{
  "name": "project1",
  "version": "1.0.0",
  "description": "Project 1",
  "main": "index.js",
  "scripts": {
    "prestart": "tsc",
    "start": "concurrently \"tsc --watch \" \"nodemon server.js startServer\"",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "license": "ISC",
  "dependencies": {
    "@types/es6-promise": "0.0.32",
    "body-parser": "^1.16.0",
    "es6-map": "^0.1.5",
    "giuseppe": "^1.2.0",
    "make-runnable": "^1.0.7",
    "request": "^2.79.0",
    "request-promise": "^4.1.1",
    "typescript": "^2.1.4"
  },
  "devDependencies": {
    "@types/chai": "^3.4.34",
    "concurrently": "^3.1.0",
    "nodemon": "^1.11.0"
  }
}

我尝试删除node_modules文件夹并使用

清除缓存
npm cache clear

然后使用

重新安装
npm install

但未能开始?可能是什么问题?

1 个答案:

答案 0 :(得分:0)

问题在于打字稿本身。这是Github上提出的问题

https://github.com/Microsoft/TypeScript/issues/18301

但现在这个问题已得到解决。

只需更新typescript模块

npm update typescript --save