RaceBase
RaceBase

Reputation: 18848

Typescript unable to find Express module

I am trying to create my first NodeJS application, however I couldn't make it work.

These are the steps I followed so far from various blogs and trying to build first nodejs app in typescript.

npm install -g express-generator
npm install -g typescript
express SampleApp
npm install -g typings
typings install dt~node --global
typings install dt~express dt~serve-static dt~express-serve-static-core --global
cd SampleApp
npm install

hello.ts

import express = require('express');
var app = express();

When I build compile the ts file with TypeScript

>>> tsc -m commonjs -t es5 hello.ts
hello.ts(1,26): error TS2307: Cannot find module 'express'.

I have gone through various resources, couldn't find the solution. I guess I don't have to copy node.d.ts and express.d.ts files manually to the project folder.

If I use nodejs and expressjs alone npm start it works fine. Typescript plugin is something I am not able to do

Can anyone help what exactly I am doing wrong here?

Upvotes: 1

Views: 6655

Answers (2)

Manjunath Bhadrannavar
Manjunath Bhadrannavar

Reputation: 163

The typescript doesn't contain the type description for express, that has to be added using the below

npm i @types/express

Upvotes: 0

RaceBase
RaceBase

Reputation: 18848

I fixed this issue by uninstalling typings package and reinstall typings with --global --save

1. npm uninstall typings --global
2. npm install typings --global
3. typings install dt~node dt~express --global --save

then typescript files are getting compiled fine.

Reported Issue: https://github.com/typings/typings/issues/543

Upvotes: 1

Related Questions