1

The Express type definitions for Typescript 2.0 result in unexpected errors when executing after running npm install @types/express and tsc -t ES6 for ES6. The code compiles fine without the ES6 flag. Can anyone explain? I also have issues with other type definitions such as ssh2.

Here are the steps to reproduce:

> mkdir humbug
> cd humbug
> touch blank.ts
> tsc blank.ts
> tsc -t ES6 .\blank.ts

Everything is fine so far.

> npm init .
...
> npm install @types/express

Things start going bad now

> tsc blank.ts
> tsc -t ES6 .\blank.ts
node_modules/@types/express/index.d.ts(16,30): error TS2307: Cannot find module 'serve-static'.
node_modules/@types/serve-static/index.d.ts(16,20): error TS2307: Cannot find module 'mime'.

Ok, well I better make sure that the types for serve-static and mime are installed.

> npm install @types/serve-static @types/mime
[email protected] C:\Users\me\Desktop\humbug
`-- (empty)

npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm ERR! code 1

Weird I got an ERR! code but the types were downloaded, Lets try compiling again

> tsc blank.ts
> tsc -t ES6 .\blank.ts
node_modules/@types/express/index.d.ts(16,30): error TS2307: Cannot find module 'serve-static'.
node_modules/@types/serve-static/index.d.ts(16,20): error TS2307: Cannot find module 'mime'.

Same error as last time.

My Environment:

  • Windows 10
  • Node v6.6.0
  • TSC 2.0.3

Other definitions with the same problem:

node_modules/@types/cors/index.d.ts(9,26): error TS2307: Cannot find module 'express'.
node_modules/@types/multer/index.d.ts(6,26): error TS2307: Cannot find module 'express'.
node_modules/@types/ssh2/index.d.ts(26,8): error TS2307: Cannot find module 'ssh2-streams'.

1 Answer 1

1

I am still learning all this stuff (being .NET programmer), but I had similar issue this afternoon and this configuration seem to be working:

{
    "compilerOptions": {
        "module": "system",
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "moduleResolution": "node",
        "sourceMap": true,
        "typeRoots": [ "node_modules/@types" ]
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules",
        "node_modules/@types",
        "**/*.spec.ts"
    ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

I think only the typeRoots is useful, in my case I needed to go up one level "typeRoots": [ "../node_modules/@types" ]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.