简体   繁体   中英

tsc error TS1110 node.d.ts Node.js v6.x

When running tsc I get a lot of errors of the form

typings/node/node.d.ts(Ln,Col): error TS1110: Type expected.

FYI: The first line of node.d.ts says

// Type definitions for Node.js v6.x

What is the cause for these errors and how to resolve them?

Steps to reproduce: In a directory having only file tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "sourceMap": true,
        "module": "commonjs",
        "outDir": "."
    }
}

next, execute the command tsd install body-parser --save , output:

- body-parser                  / body-parser
  -> express                   > express
  -> serve-static              > serve-static
  -> express-serve-static-core > express-serve-static-core
  -> node                      > node
  -> mime                      > mime

> running install..

> written 6 files:

   - body-parser/body-parser.d.ts
   - express-serve-static-core/express-serve-static-core.d.ts
   - express/express.d.ts
   - mime/mime.d.ts
   - node/node.d.ts
   - serve-static/serve-static.d.ts

The directory now has subdirectory /typings .

Next command:

$ tsc
typings/node/node.d.ts(87,23): error TS1110: Type expected.
typings/node/node.d.ts(244,57): error TS1110: Type expected.
typings/node/node.d.ts(245,48): error TS1110: Type expected.
typings/node/node.d.ts(246,50): error TS1110: Type expected.
typings/node/node.d.ts(247,60): error TS1110: Type expected.
typings/node/node.d.ts(248,45): error TS1110: Type expected.
typings/node/node.d.ts(249,37): error TS1110: Type expected.
typings/node/node.d.ts(291,57): error TS1110: Type expected.
typings/node/node.d.ts(292,48): error TS1110: Type expected.
typings/node/node.d.ts(293,50): error TS1110: Type expected.
typings/node/node.d.ts(294,60): error TS1110: Type expected.
typings/node/node.d.ts(295,45): error TS1110: Type expected.
typings/node/node.d.ts(496,54): error TS1110: Type expected.
typings/node/node.d.ts(540,57): error TS1110: Type expected.
typings/node/node.d.ts(541,48): error TS1110: Type expected.
typings/node/node.d.ts(542,50): error TS1110: Type expected.
typings/node/node.d.ts(543,61): error TS1110: Type expected.
typings/node/node.d.ts(544,65): error TS1110: Type expected.
typings/node/node.d.ts(545,60): error TS1110: Type expected.
typings/node/node.d.ts(546,45): error TS1110: Type expected.
typings/node/node.d.ts(547,37): error TS1110: Type expected.
typings/node/node.d.ts(869,35): error TS1110: Type expected.
typings/node/node.d.ts(1950,52): error TS1005: '=' expected.
typings/node/node.d.ts(1951,76): error TS1005: '=' expected.
typings/node/node.d.ts(1952,52): error TS1005: '=' expected.
typings/node/node.d.ts(1952,96): error TS1005: '=' expected.
typings/node/node.d.ts(1962,54): error TS1005: '=' expected.
typings/node/node.d.ts(1963,74): error TS1005: '=' expected.
typings/node/node.d.ts(1964,54): error TS1005: '=' expected.
typings/node/node.d.ts(1964,94): error TS1005: '=' expected.

TLDR;

npm install -g typescript

and not

npm install -g tsc

Explanation:

I noticed that Visual Studio 2015 has no issues compiling the same directory of TypeScript files so I examined the Build log (with Diagnostic verbosity under Options) and found this line:

C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe  --module CommonJS --sourcemap --target ES5 --noEmitOnError --locale en-US 

I had been using the tsc compiler installed by npm install tsc --global but its version is 1.5.3 as of today, whereas the one noted above is version 1.8.9.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM