2

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?

12
  • No experience with TS whatsoever, but generally, after running express SampleApp you need to run npm install in the generated project directory. Commented May 23, 2016 at 10:15
  • cd SampleApp then npm install Commented May 23, 2016 at 10:17
  • @arjunkori, I have done that. I am new to nodejs however I know little basics of installing packages and running things. Just trying to plugin "TypeScript" Commented May 23, 2016 at 10:21
  • is there any reason why you are installing the typings globally? :) Commented May 23, 2016 at 10:37
  • @toskv, it suggested me to install global and VS Code official blog, so i just went ahead and done that :) Commented May 23, 2016 at 10:51

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

Does not work for me. Followed steps 1-3 and even removed the entries in my Program Files(86)\Microsoft SDKS\Typescript folder. I'm using TS 1.8.
install typescript using npm install typescript -g
Tried that, and then steps 1-3 again. tsc app.ts still cannot find express using a typescript import statement like import * as express from 'express'.
created new project, setup same way and using typescript 2.1. Same issue. Typescript installed global as well.
Got it working. Reinstalled all node modules. Thanks!
0

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

npm i @types/express

Comments

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.