简体   繁体   中英

Angular2: Cannot find name 'Promise' after having installed global dependencies

I'm building an app using angular 2 and nodejs and I've installed the necessary dependencies from the package.json already. Inside of the package.json, there is a postinstall command to install the dependencies in typings.json. I was initially trying to install the es6-shim using:

"ambientDependencies": {
  "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2"
}

but running this returned the error:

npm ERR! Failed at the support-dashboard@1.0.0 typings script 'typings "install"'.

I then saw on quickstart guide for Angular that they have the following in their typings.json file:

{
  "globalDependencies": {
    "core-js": "registry:dt/core-js#0.0.0+20160602141332",
    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
    "node": "registry:dt/node#6.0.0+20160621231320"
  }
}

so I installed those dependencies since the site says:

We identified three typings file in the QuickStart, the d.ts files for core-js that brings ES2015/ES6 capabilities to our ES5 browsers

For some reason though, when I start the server, I'm still getting the error that Promise can't be found. My company gets packages from the Node repositories we have on our servers so I think that maybe the github link that has been provided for the es6 shim might not work possibly, but I'm not sure.

Is there something that has to be configured differently in order to get "Promise" to be recognized?

EDIT:

Command prompt log from running npm start :

bash-3.1$ npm start

> support-dashboard@1.0.0 start c:\MEAN_project
> concurrently "npm run tsc:w" "node server.js"

[1] Magic happens on port 8080
[0]
[0] > support-dashboard@1.0.0 tsc:w c:\MEAN_project
[0] > tsc -w
[0]
[0] node_modules/angular2/platform/browser.d.ts(78,90): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/application_ref.d.ts(38,88): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/application_ref.d.ts(92,42): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/application_ref.d.ts(151,33): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/change_detection/differs/default_keyvalue_differ.d.ts(23,15): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/core/change_detection/differs/default_keyvalue_differ.d.ts(25,16): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/core/di/reflective_provider.d.ts(103,123): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/core/di/reflective_provider.d.ts(103,165): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/core/linker/component_resolver.d.ts(8,53): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/linker/component_resolver.d.ts(12,44): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(59,148): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(100,144): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(105,139): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(106,135): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/async.d.ts(27,33): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/async.d.ts(28,45): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/collection.d.ts(1,25): error TS2304: Cannot find name 'MapConstructor'.
[0] node_modules/angular2/src/facade/collection.d.ts(2,25): error TS2304: Cannot find name 'SetConstructor'.
[0] node_modules/angular2/src/facade/collection.d.ts(4,27): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(4,39): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(7,9): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(8,30): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(11,43): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(12,27): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(14,23): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(15,25): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/collection.d.ts(100,41): error TS2304: Cannot find name 'Set'.
[0] node_modules/angular2/src/facade/collection.d.ts(101,22): error TS2304: Cannot find name 'Set'.
[0] node_modules/angular2/src/facade/collection.d.ts(102,25): error TS2304: Cannot find name 'Set'.
[0] node_modules/angular2/src/facade/lang.d.ts(4,17): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/lang.d.ts(5,17): error TS2304: Cannot find name 'Set'.
[0] node_modules/angular2/src/facade/lang.d.ts(71,59): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/facade/promise.d.ts(2,14): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(8,32): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(9,38): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(10,35): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(10,93): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(11,34): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(11,50): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(12,32): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(12,149): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/facade/promise.d.ts(13,43): error TS2304: Cannot find name 'Promise'.
[0] node_modules/angular2/src/platform/browser/browser_adapter.d.ts(75,33): error TS2304: Cannot find name 'Map'.
[0] node_modules/angular2/src/platform/dom/dom_adapter.d.ts(85,42): error TS2304: Cannot find name 'Map'.
[0] node_modules/rxjs/Observable.d.ts(10,66): error TS2304: Cannot find name 'Promise'.
[0] node_modules/rxjs/Observable.d.ts(66,60): error TS2304: Cannot find name 'Promise'.
[0] node_modules/rxjs/Observable.d.ts(66,70): error TS2304: Cannot find name 'Promise'.
[0] 8:52:59 AM - Compilation complete. Watching for file changes.

I think the problem might not lie in your node.js setup, but in the version of your browser.

A Promise is a construct in the new ECMAScript 2015 (ES6) standard. Is it possible that you are using an old browser. Because new Browsers should recognize it .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM