1

I have PHP and JavaScript background and never worked with nodejs or angular js with full hand , just a basic understanding of these js.

I started to learn angular js 2 but find very difficulties to set up first example.

node v 5.6.0 and npm version 3.7.2 on ubuntu 14.04

I am following this article with a change -- that tsd has been deprecated so used typings instead of tsd. below is my folder structure. angular 2 set up

But when I run gulp buildServer on terminal it gives below errors

Gulp Error

I may be doing very basic error , kindly help me to solve this and if required more information then tell me.

server.ts has below code

import express = require('express');
import path = require('path');
var port: number = process.env.PORT || 3000;
var app = express();

app.use('/app', express.static(path.resolve(__dirname, 'app')));
app.use('/libs', express.static(path.resolve(__dirname, 'libs')));

var renderIndex = (req: express.Request, res: express.Response) => {
    res.sendFile(path.resolve(__dirname, 'index.html'));
}

app.get('/*', renderIndex);

var server = app.listen(port, function() {
    var host = server.address().address;
    var port = server.address().port;
    console.log('This express app is listening on port:' + port);
});
xkeshav
  • 53,360
  • 44
  • 177
  • 245

2 Answers2

1

It says cannot find module 'path' and then again with http and so on. Also errors with duplicate identifier in my experience are due to using old version of npm because since npm v3.0 it tries to make all dependencies flat.

I'd try to rm -rf node_modules, install newest stable node and npm, run again npm install and then try running your gulp. Or at least check what are your npm and node versions.

martin
  • 93,354
  • 25
  • 191
  • 226
  • my npm version is 1.3.7 and nodejs version is v0.10.25 on ubuntu 14.04 – xkeshav Feb 10 '16 at 16:29
  • I have not much knowledge of node..my assumption is that this may be because there is `node_modules` folder but we haven't write in the code there where is the express and other module in server.ts – xkeshav Feb 10 '16 at 16:31
  • That's pretty old, try to upgrade both and then re-run it. Typescript compiler looks into your `node_modules` directory by default, so you don't need to worry about it. – martin Feb 10 '16 at 16:32
  • would that run over ubuntu 14.04 ? do i need to uninstall both node and npm? – xkeshav Feb 10 '16 at 16:32
  • I don't know how to install it on Ubuntu. Maybe have a look here https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions. – martin Feb 10 '16 at 16:33
  • I have updated both node and npm but issues are still same. do i need to delete node_modules folder reside in the sample folder – xkeshav Feb 10 '16 at 16:50
  • 1
    I'd recommend removing the old `node_modules` and running `npm install` again. – martin Feb 11 '16 at 06:54
1

You need to get the type definitions for node and server-static.

typings install node --ambient --save
typings install serve-static --ambient --save
typings install mime --ambient --save

You need mime since serve-static relys on it.

Joshua F
  • 878
  • 8
  • 11
  • Thanks , it removed the given error but gives 655 lines of errors showing `server/typings/main/ambient/node/node.d.ts(...,..): error TS2300: Duplicate identifier ......` – xkeshav Feb 12 '16 at 16:23
  • will you please see my new problem here : http://stackoverflow.com/questions/35368497/angular-2-multiple-times-error-ts2300-duplicate-identifier – xkeshav Feb 12 '16 at 17:58