4

I am getting "Cannot find name 'Promise' errors when trying to run an angular2-express app "npm run develop"

node_modules/@angular/common/src/directives/ng_class.d.ts(81,34):error TS2304: Cannot find name 'Set'.
[1] node_modules/@angular/common/src/facade/lang.d.ts(11,17): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/common/src/facade/lang.d.ts(12,17): error TS2304: Cannot find name 'Set'.
[1] node_modules/@angular/common/src/facade/lang.d.ts(67,59): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/common/src/pipes/async_pipe.d.ts(41,38): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_init.d.ts(16,18): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_ref.d.ts(99,88): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_ref.d.ts(134,67): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_ref.d.ts(150,109): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_ref.d.ts(202,67): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_ref.d.ts(204,109): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_ref.d.ts(236,42): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/application_ref.d.ts(331,33): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(1,25): error TS2304: Cannot find name 'MapConstructor'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(2,25): error TS2304: Cannot find name 'SetConstructor'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(4,27): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(4,39): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(7,9): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(8,30): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(11,43): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(12,27): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(14,23): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(15,25): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(100,41): error TS2304: Cannot find name 'Set'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(101,22): error TS2304: Cannot find name 'Set'.
[1] node_modules/@angular/core/src/facade/collection.d.ts(102,25): error TS2304: Cannot find name 'Set'.
[1] node_modules/@angular/core/src/facade/lang.d.ts(11,17): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/facade/lang.d.ts(12,17): error TS2304: Cannot find name 'Set'.
[1] node_modules/@angular/core/src/facade/lang.d.ts(67,59): error TS2304: Cannot find name 'Map'.
[1] node_modules/@angular/core/src/linker/compiler.d.ts(47,76): error TS2304: Cannot find name 'Promise'.
[1] node_modules/@angular/core/src/linker/compiler.d.ts(62,57): error TS2304: Cannot find name 'Promise'.

.....
.....

These are the contents of several files

package.json

{
  "name": "angular2-express-starter",
  "version": "1.0.0",
  "description": "Starter application of Angular2 on Express",
  "main": "gulpfile.js",
  "private": true,
  "scripts": {
    "develop": "concurrently \"tsc -w -p ./server\" \"tsc -w -p ./client\" \"nodemon ./server/bin/www\" ",
    "twc:client:w": "tsc -w -p ./client",
    "twc:server:w": "tsc -w -p ./server",
    "typings": "typings install",
    "bundle": "node tools/builder.js",
    "bundle:prod": "node tools/builder.js --prod",
    "postinstall": "typings install && tsc -p ./server"
  },
  "engines": {
    "node": ">= 5.4.1 < 6"
  },
  "author": "Vlado Tešanović",
  "license": "MIT",
  "dependencies": {
    "bcrypt": "^0.8.7",
    "body-parser": "~1.13.2",
    "cookie-parser": "~1.3.5",
    "express": "^4.13.4",
    "express-jwt": "^3.3.0",
    "jsonwebtoken": "^5.7.0",
    "jwt-simple": "*",
    "morgan": "*",
    "mysql": "^2.11.1",
    "serve-favicon": "~2.3.0",
    "typescript": "^1.8.10",
    "typings": "^1.3.2"
  },
  "devDependencies": {
    "@angular/common": "2.0.0-rc.5",
    "@angular/compiler": "2.0.0-rc.5",
    "@angular/core": "2.0.0-rc.5",
    "@angular/forms": "0.3.0",
    "@angular/http": "2.0.0-rc.5",
    "@angular/platform-browser": "2.0.0-rc.5",
    "@angular/platform-browser-dynamic": "2.0.0-rc.5",
    "@angular/router": "^3.0.0-rc.1",
    "@angular/router-deprecated": "^2.0.0-rc.2",
    "@angular/upgrade": "2.0.0-rc.5",
    "angular2-in-memory-web-api": "0.0.15",
    "angular2-jwt": "^0.1.18",
    "concurrently": "^2.2.0",
    "core-js": "^2.4.1",
    "ng-semantic": "^1.0.33",
    "nodemon": "^1.9.1",
    "reflect-metadata": "^0.1.3",
    "retyped-bcrypt-tsd-ambient": "0.0.0-0",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "0.19.27",
    "systemjs-builder": "^0.15.17",
    "yargs": "^4.8.1",
    "zone.js": "^0.6.12"
  }
}

typings.json

{
    "globalDependencies": {
        "body-parser": "registry:dt/body-parser#0.0.0+20160619023215",
        "es6-collections": "registry:dt/es6-collections#0.5.1+20160316155526",
        "es6-promise": "registry:dt/es6-promise#0.0.0+20160614011821",
        "express": "registry:dt/express#4.0.0+20160708185218",
        "express-serve-static-core": "registry:dt/express-serve-static-core#4.0.0+20160715232503",
        "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
        "jquery": "registry:dt/jquery#1.10.0+20160704162008",
        "mime": "registry:dt/mime#0.0.0+20160316155526",
        "node": "registry:dt/node#6.0.0+20160720070758",
        "serve-favicon": "registry:dt/serve-favicon#0.0.0+20160316155526",
        "serve-static": "registry:dt/serve-static#0.0.0+20160606155157"
      },
      "dependencies": {
        "jsonwebtoken": "registry:npm/jsonwebtoken#5.5.4+20160208220328"
      }
    }

main.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule }              from './components/app.module';

platformBrowserDynamic().bootstrapModule(AppModule);

app.ts

import { Component } from "@angular/core";
import { ROUTER_DIRECTIVES } from '@angular/router';
import { Header } from './header/header'
import { Footer } from './footer/footer'
import { UserService } from "../services/user.service";

@Component({
    directives: [ ROUTER_DIRECTIVES, Header, Footer ],
    selector: "app",
    templateUrl: "client/components/app.html",
    styles: [
        './rajd-theme.css'
    ]
})
export class App {
    constructor(private userService: UserService) {

    }
}

app.module.ts

import { NgModule }       from '@angular/core';
import { BrowserModule  } from '@angular/platform-browser';
import { FormsModule  } from '@angular/forms';
import { RouterModule  } from '@angular/router';

import { App }   from './app.ts';

@NgModule({
    declarations: [App],
    imports:      [
        BrowserModule,
        FormsModule,
        RouterModule
    ],
    bootstrap:    [App],
})
export class AppModule {}

Note that I am using angular rc5 and NgModules.

2
  • I guess this answer should help you Commented Aug 20, 2016 at 9:27
  • already tried this, didn't work @PankajParkar Commented Aug 20, 2016 at 9:33

3 Answers 3

2

I had the same problem with this, but I managed to fix it by changing "target": "es2015" in tsconfig.json. I cannot tell you why this fixed the issue for me, but it worked.

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

Comments

1

IF you are experience cannot find name error., mostly you have changed some files in the base setup or may be you didn't finish the node package installation successfully. Angular2 doesn't use typings package anymore.

solution:

clone the following repository https://github.com/angular/quickstart run npm install in the project directory and make sure it finish successfully now copy and config your app project folders into the cloned new folder now this will work perfectly.

Comments

1

You could try adding "lib": ["es6"] to your tsconfig.json config file. If you're using browser symbols like window and such, you could also try "lib": ["es6", "dom"]

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.