Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error TS2304: Cannot find name 'Promise'

Hello guys I went through all solution avaialble on stackoverflow. But none of work for me. Hence posting question. tsconfig.json

{
  "version":"2.13.0",
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": true,
    "noImplicitAny": false    
  },
  "exclude": [
        "node_modules"
    ]
}

package.json

{
  "name": "anguapp",
  "version": "1.0.0",
  "description": "Angular2 Gulp Typescript and Express",
  "main": "dist/server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "postinstall": "gulp build"
  },
  "keywords": [],
  "author": "UK",
  "license": "MIT",
  "dependencies": {
    "angular2": "2.0.0-beta.17",
     "es6-promise": "3.2.1",
    "es6-shim": "0.35.1",
    "body-parser":"1.15.2",
    "express": "4.13.3",
    "gulp-concat": "2.6.0",
    "reflect-metadata": "0.1.8",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "0.19.37",
    "zone.js": "0.6.17",
    "mongodb" :"2.2.8",
     "ejs" : "~0.8.5"          
    },
  "devDependencies": {
    "del": "2.2.2",
    "gulp": "3.9.1",
    "gulp-concat": "2.6.0",
    "gulp-sourcemaps": "1.6.0",
    "gulp-typescript": "2.13.0",
    "run-sequence": "1.1.5"
  }
}

While doing gulp i am getting following errors.

[12:39:43] Using gulpfile D:\Repository\documents\personal\abha-du\gulpfile.js
[12:39:43] Starting 'build'...
[12:39:43] Starting 'clean'...
[12:39:43] Finished 'clean' after 66 ms
[12:39:43] Starting 'build:server'...
[12:39:45] Finished 'build:server' after 2.18 s
[12:39:45] Starting 'build:index'...
[12:39:46] Finished 'build:index' after 21 ms
[12:39:46] Starting 'build:app'...
D:/Repository/documents/personal/abha-du/node_modules/angular2/platform/browser.
d.ts(78,90): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/common/direct
ives/ng_class.d.ts(72,35): error TS2304: Cannot find name 'Set'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/common/pipes/
async_pipe.d.ts(25,38): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/core/applicat
ion_ref.d.ts(38,88): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/core/applicat
ion_ref.d.ts(92,42): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/core/applicat
ion_ref.d.ts(151,33): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/core/change_d
etection/differs/default_keyvalue_differ.d.ts(23,15): error TS2304: Cannot find
name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/core/change_d
etection/differs/default_keyvalue_differ.d.ts(25,16): error TS2304: Cannot find
name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/core/di/refle
ctive_provider.d.ts(103,123): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/core/di/refle
ctive_provider.d.ts(103,165): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/core/linker/c
omponent_resolver.d.ts(8,53): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/core/linker/c
omponent_resolver.d.ts(12,44): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/core/linker/d
ynamic_component_loader.d.ts(59,148): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/core/linker/d
ynamic_component_loader.d.ts(100,144): error TS2304: Cannot find name 'Promise'.

D:/Repository/documents/personal/abha-du/node_modules/angular2/src/core/linker/d
ynamic_component_loader.d.ts(105,139): error TS2304: Cannot find name 'Promise'.

D:/Repository/documents/personal/abha-du/node_modules/angular2/src/core/linker/d
ynamic_component_loader.d.ts(106,135): error TS2304: Cannot find name 'Promise'.

D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/async.
d.ts(27,33): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/async.
d.ts(28,45): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/collec
tion.d.ts(1,25): error TS2304: Cannot find name 'MapConstructor'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/collec
tion.d.ts(2,25): error TS2304: Cannot find name 'SetConstructor'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/collec
tion.d.ts(4,27): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/collec
tion.d.ts(4,39): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/collec
tion.d.ts(7,9): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/collec
tion.d.ts(8,30): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/collec
tion.d.ts(11,43): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/collec
tion.d.ts(12,27): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/collec
tion.d.ts(14,23): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/collec
tion.d.ts(15,25): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/collec
tion.d.ts(100,41): error TS2304: Cannot find name 'Set'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/collec
tion.d.ts(101,22): error TS2304: Cannot find name 'Set'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/collec
tion.d.ts(102,25): error TS2304: Cannot find name 'Set'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/lang.d
.ts(4,17): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/lang.d
.ts(5,17): error TS2304: Cannot find name 'Set'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/lang.d
.ts(71,59): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/promis
e.d.ts(2,14): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/promis
e.d.ts(8,32): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/promis
e.d.ts(9,38): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/promis
e.d.ts(10,35): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/promis
e.d.ts(10,93): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/promis
e.d.ts(11,34): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/promis
e.d.ts(11,50): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/promis
e.d.ts(12,32): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/promis
e.d.ts(12,149): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/facade/promis
e.d.ts(13,43): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/http/headers.
d.ts(43,59): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/http/url_sear
ch_params.d.ts(11,16): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/platform/brow
ser/browser_adapter.d.ts(75,33): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/platform/dom/
dom_adapter.d.ts(85,42): error TS2304: Cannot find name 'Map'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/direct
ives/router_outlet.d.ts(27,54): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/direct
ives/router_outlet.d.ts(33,51): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/direct
ives/router_outlet.d.ts(38,56): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/direct
ives/router_outlet.d.ts(47,65): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/direct
ives/router_outlet.d.ts(58,60): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/instru
ction.d.ts(124,34): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/instru
ction.d.ts(148,25): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/instru
ction.d.ts(164,34): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/instru
ction.d.ts(167,25): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/interf
aces.d.ts(21,107): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/interf
aces.d.ts(39,104): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/interf
aces.d.ts(57,109): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/interf
aces.d.ts(80,109): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/interf
aces.d.ts(102,114): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/lifecy
cle/lifecycle_annotations.d.ts(29,100): error TS2304: Cannot find name 'Promise'
.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/route_
config/route_config_impl.d.ts(101,19): error TS2304: Cannot find name 'Promise'.

D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/route_
definition.d.ts(20,20): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/route_
definition.d.ts(35,20): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/route_
registry.d.ts(52,66): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/router
.d.ts(56,50): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/router
.d.ts(68,46): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/router
.d.ts(86,45): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/router
.d.ts(99,34): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/router
.d.ts(107,64): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/router
.d.ts(112,85): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/router
.d.ts(120,70): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/router
.d.ts(128,43): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/router
.d.ts(132,29): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/router
.d.ts(138,19): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/angular2/src/router/router
.d.ts(146,70): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/rxjs/Observable.d.ts(10,66
): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/rxjs/Observable.d.ts(66,60
): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/rxjs/Observable.d.ts(66,70
): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/rxjs/operator/toPromise.d.
ts(7,59): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/rxjs/operator/toPromise.d.
ts(7,69): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/rxjs/operator/toPromise.d.
ts(9,9): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/rxjs/operator/toPromise.d.
ts(10,26): error TS2304: Cannot find name 'Promise'.
D:/Repository/documents/personal/abha-du/node_modules/rxjs/operator/toPromise.d.
ts(10,36): error TS2304: Cannot find name 'Promise'.
[12:39:47] TypeScript: 86 semantic errors
[12:39:47] TypeScript: emit succeeded (with errors)
[12:39:47] Finished 'build:app' after 1.93 s
[12:39:47] Starting 'build:home'...
[12:39:47] Finished 'build:home' after 7.17 ms
[12:39:47] Finished 'build' after 4.23 s
[12:39:47] Starting 'default'...
[12:39:47] Finished 'default' after 12 µs

Please help me to solve these TS2304: Cannot find name 'Promise' errors

like image 470
Ujwal Khairnar Avatar asked Aug 24 '16 07:08

Ujwal Khairnar


1 Answers

You just need to change your target to es6 inside your tsconfig.json to resolve this issue.

{
  "version":"2.13.0",
  "compilerOptions": {
    "target": "es6", //<- change here
    ......
  },
  "exclude": [
        "node_modules"
    ]
}

Other way what you can do is, you need to make sure you have es6-shim.js have been referred there on page and then follow this answer that would not need to change target option.

like image 87
Pankaj Parkar Avatar answered Oct 21 '22 08:10

Pankaj Parkar