How to install express in typings?
Asked Answered
T

5

16

I am trying to use expressjs in my app.

After installing it using typings install express --ambient --save, I run tsc, but I get two errors:

typings/main/ambient/express/index.d.ts(17,34): error TS2307: Cannot find module 'serve-static'. typings/main/ambient/express/index.d.ts(18,27): error TS2307: Cannot find module 'express-serve-static-core'.

So, I tried to install both:

typings install serve-static --ambient --save
typings install express-serve-static --ambient --save

and then I run tsc again, but get one more error:

typings/main/ambient/serve-static/index.d.ts(79,24): error TS2307: Cannot find module 'mime'.

How can I solve these problems? How can I install all dependencies of express automatically?

Toxophilite answered 16/3, 2016 at 14:4 Comment(0)
C
17

With Typescript 2.0(https://blogs.msdn.microsoft.com/typescript/2016/09/22/announcing-typescript-2-0/), now it is different:

If you install typescript with the following command:

npm install -g [email protected]

You will have to install express typings with command

npm install --save @types/express

Instead of typings getting installed with ambient/global like in earlier releases. The typings get installed in node_modules/@types/express directory

Your package.json will have the following fragment after doing npm install of types :

"dependencies": {
    "@types/express": "^4.0.33"
  }
Crotchet answered 11/10, 2016 at 18:17 Comment(1)
must the version of @types/express be the very same as the one for express?Kingfish
A
10
{
  "globalDependencies": {
    "express": "registry:dt/express#4.0.0+20160708185218",
    "express-serve-static-core": "registry:dt/express-serve-static-core#4.0.0+20160715232503",
    "mime": "registry:dt/mime#0.0.0+20160316155526",
    "node": "registry:dt/node#6.0.0+20160621231320",
    "serve-static": "registry:dt/serve-static#0.0.0+20160606155157"
  }
}

This is my working Typings.json

Aruwimi answered 21/7, 2016 at 9:22 Comment(2)
This whole time.... in my typings.json for my error: -> "registry:dt/express-serve-static-core#0.0.0+20160715232503" somehow I got version 0.0.0 and had to manually change it to 4.0.0 then run typings install dt~express-serve-static-core --global --saveIncensory
Why aren't these installed along with express? Are these peer dependencies?Kellum
F
8

I just ran into this myself and I believe is a duplicate from :

Importing node and express with typings in TypeScript

I installed both serve-static and express-serve-static then got errors stating that I was missing 'mime' and 'http'.

I had to install node typings to resolve the missing http reference and mime typings to resolve mime missing reference.

typings install mime --ambient --save
typings install node --ambient --save
Franciscafranciscan answered 17/3, 2016 at 1:23 Comment(2)
With typings 1.0, I believe this is now: typings install dt~mime --global --saveVesuvius
And now (Oct 2016) the correct command is typings install mime --global --save --source dtDeventer
A
5

The command that worked for me (the day I posted) was : typings install dt~express --global --save (ambient was replaced by global)

To find other related module you can use the command typings search express (it also give you the source info)

Amphiarthrosis answered 1/8, 2016 at 16:18 Comment(0)
G
0

I'v run into this issue myself and found out you also have to have the actual nodeJS module installed as well as its typing.

So when you have correclty configured typescript and your project, you need ot install both the nodeJS dependency as well as the @types dependecy.

npm install express --save

npm install --save @types/express

Gessner answered 12/1, 2017 at 15:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.